A computer has no minus sign. Numbers sit on a wheel that wraps, so going back 3 lands on the same place as going forward by the rest of the wheel. Both wheels start at 4 and compute 4 − 3 = 1.
Signed-magnitude uses the leftmost bit as the sign and the rest as the value, but it has two
zeros (0000 and 1000) and needs separate circuits for addition and
subtraction. Two's complement avoids both: the wheel wraps, so subtraction is addition.
10 − 3. On the binary wheel, 1101 (13)
is 16 − 3. Those are the ten's and two's complements of 3. Adding a complement
gives the same result as subtracting the original, so hardware can drop subtraction
circuits entirely and always add.
For k bits:
1101.1010.
For large k, computing 2k − I is slow. The mechanical version:
0101. Flip to 1010. Add 1 to get 1011.1011.
1100?0011, add 1 to get 0100 = 4.1100 = −4.
With k bits:
4 bits: −8 to +7. 8 bits: −128 to +127. 32 bits: about ±2.1 billion.
| Binary | Signed value |
|---|
In 4 bits, 1000 is −8, but there is no +8 (the largest positive is +7).
Applying the shortcut to 1000: flip to 0111, add 1, back to
1000. Negating the most negative value returns itself.
All four use 4-bit two's complement. Binary answers are exactly 4 digits.
1. Write −5 in 4-bit two's complement.
2. The pattern 1010 is which decimal value?
3. Compute 6 + (−4) in 4-bit two's complement.
4. Compute 0111 + 0001 in 4 bits.