This week's book giveaway is in the Agile and other Processes forum.We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login Win a copy of The Mikado Method this week in the Agile and other Processes forum!

# characters in a byte

Ranch Hand

Joined: Sep 13, 2005
Posts: 238

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).

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9946

6

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

4
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

1
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

19

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).

Thanks