Two’s complement
Two’s complement is the usual way to represent negative integers. The top bit shows the sign.
Rules
- Write the magnitude in binary
- Invert every bit
- Add 1
- n bits: range −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
Your turn
Three problems on this topic. Spaces don’t matter.
- 1 · Two’s complement
- 2
- 3
Represent the number in 8-bit two’s complement.
−41
Bit pattern
Worked example
What value does this 12-bit two’s complement have?
1011 1111 1001
Worked solution
- 1Magnitude in binary: 0100 0000 0111
- 2Invert every bit: 1011 1111 1000
- 3Add 1: 1011 1111 1001
Typical mistake: After inverting, add 1, otherwise it is one’s complement.
Common questions
Why two’s complement?
Addition works without special cases, and there is only one zero.
