The adder/subtractor
One control bit turns your adder into a subtractor too — no second circuit, just two's complement and a row of XOR gates.
Built from first principles.
Before you start
What you need first
- Two's complement — negate by "invert all bits, then add 1".
- The ripple-carry adder — the n-bit adder we'll reuse.
- XOR gate — used here as a controllable inverter.
What you'll be able to do
- Subtract using an adder:
A − B = A + B′ + 1. - Use XOR as a controlled inverter driven by a mode bit M.
- Read the one-circuit adder/subtractor and trace add vs subtract.
Subtract by adding the complement
From two's complement, negating B means invert every bit and add 1.
So subtraction is just an addition in disguise:
We already have an n-bit adder. To subtract, we need two changes: feed it B′
(every bit of B inverted) instead of B, and add the extra +1 by
setting the adder's carry-in to 1. Both can be switched by a single mode bit M.
XOR: an inverter you can switch on
The key trick is one property of XOR:
So Bi ⊕ M passes B straight through when M = 0, and
inverts it when M = 1. Put one XOR on each B bit, tie the other input of every
XOR to M, and also feed M into the carry-in. That one bit now chooses the operation:
What M does
| M | B into adder | Carry-in | Adder computes | Operation |
|---|---|---|---|---|
| 0 | B ⊕ 0 = B | 0 | A + B + 0 | add |
| 1 | B ⊕ 1 = B′ | 1 | A + B′ + 1 | subtract (A − B) |
Compute 6 − 3 in 4-bit two's complement (M = 1)
Take A = 0110 (6) and B = 0011 (3). With M = 1 the circuit inverts
B and sets carry-in to 1:
Now the adder computes A + B′ + 1:
That's 5 bits. In 4-bit two's complement we drop the carry-out (the leading 1):
✏️ Try it yourself
(a) Rewrite A − B as an addition. (b) What is B ⊕ 1? (c) What two
things does setting M = 1 do? (d) Compute 5 − 5 in 4 bits by the complement
method — give the 4-bit result.
Recap — the whole topic on one screen
| Idea | What you own now |
|---|---|
| Subtract = add | A − B = A + B′ + 1 |
| Controlled inverter | B ⊕ M: pass when M=0, invert when M=1 |
| The circuit | n XORs on B + an n-bit adder, with M tied to carry-in |
| Mode bit | M = 0 adds, M = 1 subtracts |