views:

60

answers:

1

The Java data type byte for example holds data from -128 to 127 in a single byte on storage. To enable to distingush between - 1 to -128 from 0 to 127 would require extra data which would take the datatype obver its allocated storage. Admittedly it would only take 1 extra bit but it still goes over.

How does java do this?

+9  A: 
Joey
Thanks, i dont know what that is but now i can look it up, didnt know where to start.
chrisg
Also, this isn't really java-specific. Lots of languages store integers this way.
uckelman
Actually it's more machine-specific, I think. But yes, most architectures do it this way. Java just guarantees that for you.
Joey
I get it, as pos numbers only ever go upto 127 then the msb will ever be 0, therefore this may be used to indicate signing, the only time it will ever change to 1 will be when 128 is reached, which only ever occurs on negetive signed numbers. Thanks. A bit more to it than that i know, but i think i get the idea.
chrisg