0345. Are signed integers stored differently than unsigned integers?

 

If an integer (or character) is unsigned (meaning it must be zero or larger), we can use all of the bits to represent the value. If an integer or character is signed that means that it may (or may not) take on negative values (a binary condition). Therefore, we need only 1-bit  to indicate whether it is negative or not.

 

If we are storing a (signed) character (on 8-bits), we assign 1-bit as a sign, and store the value on the remaining 7-bits. If we are storing an integer on 16-bits, we assign 1-bit as a sign, and store the value on the remaining 15-bits. If we are storing an integer on 32-bits, we assign 1-bit as a sign, and store the value on the remaining 31-bits.