
Complements of Numbers
Complements let us subtract using only addition — the trick behind digital arithmetic.
Description
An encoding of negative numbers so subtraction becomes addition of a complement. Building one adder is cheaper than building both an adder and a separate subtractor. 2's complement = invert all bits, then add 1. Then just add as usual and discard the final carry.
- Invert every bit (0↔1).
- Two representations of zero exist (00…0 and 11…1).
- 1's complement then add 1.
- Single zero; range for n bits is −2ⁿ⁻¹ to 2ⁿ⁻¹−1.
- Subtraction becomes addition: A − B = A + (2's complement of B).
- What: An encoding of negative numbers so subtraction becomes addition of a complement.
- Why: Building one adder is cheaper than building both an adder and a separate subtractor.
- How: 2's complement = invert all bits, then add 1. Then just add as usual and discard the final carry.
- Where: The ALU of essentially every CPU; signed integers in C, Java, Verilog, etc.
- When: Whenever signed arithmetic or subtraction is performed in hardware.
At a glance
What
An encoding of negative numbers so subtraction becomes addition of a complement.
Why
Building one adder is cheaper than building both an adder and a separate subtractor.
How
2's complement = invert all bits, then add 1. Then just add as usual and discard the final carry.
Where
The ALU of essentially every CPU; signed integers in C, Java, Verilog, etc.
When
Whenever signed arithmetic or subtraction is performed in hardware.
Think of it like…
Like a car odometer rolling backwards: from 0000 one tick back gives 9999, which everyone reads as '−1'. Two's complement is that same wrap-around trick, in binary.
1's complement
- Invert every bit (0↔1).
- Two representations of zero exist (00…0 and 11…1).
2's complement
- 1's complement then add 1.
- Single zero; range for n bits is −2ⁿ⁻¹ to 2ⁿ⁻¹−1.
- Subtraction becomes addition: A − B = A + (2's complement of B).
4-bit signed encodings
| Decimal | Sign-magnitude | 1's complement | 2's complement |
|---|---|---|---|
| +5 | 0101 | 0101 | 0101 |
| −5 | 1101 | 1010 | 1011 |
| 0 | 0000 / 1000 | 0000 / 1111 | 0000 |
| −8 | — | — | 1000 |
Only 2's complement has a single zero and an extra negative value.
Complement machine
▶ live simulatorOriginal (20)
1's complement (invert)
2's complement (invert + 1) → signed -20
The 5 Whys
- 1
Why complements? To subtract without a dedicated subtractor circuit.
- 2
Why avoid a subtractor? Extra hardware costs area, power, and design time.
- 3
Why does that cost matter? Every saved gate multiplies across millions of chips.
- 4
Why reuse the adder? Subtraction = adding a negative; complements make the negative.
- 5
Root cause: 2's complement makes one adder do all signed arithmetic — minimal hardware.
Cheat sheet
Working principle
- 2's complement = invert all bits, then add 1. Then just add as usual and discard the final carry.
- An encoding of negative numbers so subtraction becomes addition of a complement.
Formulas & Boolean expressions
- Single zero; range for n bits is −2ⁿ⁻¹ to 2ⁿ⁻¹−1.
- Subtraction becomes addition: A − B = A + (2's complement of B).
Key facts
- Invert every bit (0↔1).
- 1's complement then add 1.
Why it exists
- Root cause: 2's complement makes one adder do all signed arithmetic — minimal hardware.