| Author |
characters in a byte
|
Muhammad Imad Qureshi
Ranch Hand
Joined: Sep 13, 2005
Posts: 238
|
|
Someone asked me following questions and I didn't know the answer
If you have to store a ticker, how many characters can you store in a 4 byte integer.
I thought that each byte will have 8 bits so the answer would be 32. But apparently that is not correct. She told me the correct answer is 2 raise to the power of 32 and then divide by 26 (for 26 alpha characters).
Can someone please explain?
Thanks
Imad
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
a four-byte integer does have 32 bits - and each one can be 'on' or 'off'. That gives you 2^32 possible combinations of bits.
But I'm not sure how she got the "divide by 26" part. That doesn't make sense to me.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
|
Surely it would be (int) (32 * log2 / log 26)? But that would be awkward to implement: easiest done by using base 26 numbers.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
|
|
Besides, a ticker will need 26 alpha and 10 numeric characters.
Or you could use Baudot which uses only 5 bits so you could get 6 characters in 30bits
Bill
|
Java Resources at www.wbrogden.com
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Muhammad Imad Qureshi wrote:Someone asked me following questions and I didn't know the answer
If you have to store a ticker, how many characters can you store in a 4 byte integer.
I thought that each byte will have 8 bits so the answer would be 32. But apparently that is not correct. She told me the correct answer is 2 raise to the power of 32 and then divide by 26 (for 26 alpha characters).
Can someone please explain?
Thanks
Imad
Working out the math... "2 raise to the power of 32 and then divide by 26 (for 26 alpha characters)" --> (2 ^ 32) / 26 --> 165,191,049 characters.
So, basically, a 4 byte integer, should hold enough information to fill an encyclopedia. Hmmm... there is definitely something wrong here...
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: characters in a byte
|
|
|