next up previous
Next: How do you figure Up: Content Questions Previous: Why are base 2,

In the 2's complement, how do you tell a number is negative and not a different positive number?

In 2's complement, negative numbers always have a 1 as the most significant (leftmost) bit. If you are storing positive numbers in $n$ bits, you can store from 0 to $2^n-1$. In contrast, in 2's complement you can only store up to $2^{n-1}-1$ positive numbers, instead going from -$2^{n-1}$ to $2^{n-1}-1$.

As a concrete example of this, take 8 bits. If you are storing just positive integers, your numbers go from $0_{10} = (00000000)_2$ to $255_{10}=(111111111)_2$, i.e., 0 to 255. If you are storing numbers with a 2's complement convention, with 8 bits your numbers go from $-(128)_{10} = (10000000)_{2,{\rm 2's complement}}$ to $127_{10}=(01111111)_{2}$ (a total of 256 numbers represented). Note that $+128$ can't be represented in 8 bits in 2's complement, since the meaning of $(10000000)_2$, the nominal positive representation of $128_{10}$, is actually $-(128)_{10}$ in 2's complement.


next up previous
Next: How do you figure Up: Content Questions Previous: Why are base 2,
Kate Scholberg 2017-04-12