Logo
All chapters
Volume II: Digital Logic  ›  Digital Systems & Binary Numbers

Complements of Numbers

Complements let us subtract using only addition — the trick behind digital arithmetic.

PrevOctal & Hexadecimal
NextSigned Binary Numbers

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

DecimalSign-magnitude1's complement2's complement
+5010101010101
−5110110101011
00000 / 10000000 / 11110000
−81000

Only 2's complement has a single zero and an extra negative value.

Complement machine

▶ live simulator

Original (20)

0
0
0
1
0
1
0
0

1's complement (invert)

1
1
1
0
1
0
1
1

2's complement (invert + 1) → signed -20

1
1
1
0
1
1
0
0

The 5 Whys

  1. 1

    Why complements? To subtract without a dedicated subtractor circuit.

  2. 2

    Why avoid a subtractor? Extra hardware costs area, power, and design time.

  3. 3

    Why does that cost matter? Every saved gate multiplies across millions of chips.

  4. 4

    Why reuse the adder? Subtraction = adding a negative; complements make the negative.

  5. 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.
PrevOctal & Hexadecimal
NextSigned Binary Numbers