MSB
If part of determining a negative number is inverting the bits, how can Java determine if a number is positive or negative?
Data types in Java each have a certain number of bytes. * This is important for signed data types because the left-most bit, or most significant bit tells whether a number is positive or negative.
| MSB | Sign |
|---|---|
| 0 | positive |
| 1 | negative |
With the left-most bit now reserved for positive or negative, we can determine the maximum and minimum values for byte.
| MSB | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
| 0 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The maximum value for a byte is 127.
Recall that -1 is 11111111.
* The most negative byte possible is 10000000 - this value is -128.
Practice Exercise¶
The char data type is not signed. There is no such thing as a negative character.