Lesson 5 of 13
Gates that do maths: the adder
Explain how a few gates wired together add two binary numbers, carry and all — showing arithmetic is just logic, not magic.
01 · Learn · the idea
Here is something that should bother you. Your computer adds numbers billions of times a second, and it has no idea what a number is. It cannot count. It does not understand “plus.” There is no part of it that knows six and three make nine. And yet it gets the sum right every single time. How?
The answer is the quiet trick at the heart of every machine: you can wire a handful of switches so that the on/off pattern coming out equals the sum of the patterns going in. Nobody inside the circuit knows they are adding. The wiring just makes it so. Arithmetic, it turns out, is not a kind of thinking. It is a kind of plumbing.
Adding one column is a yes-or-no job
Forget big numbers for a moment. Start with the smallest possible sum: one binary digit plus one binary digit. There are only four cases.
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = ?
The first three are easy. The fourth is the interesting one. One plus one is two — but in binary (from item 2) two is written 10. You can’t fit 10 in a single column. So the column shows a 0, and you carry a 1 into the next column to the left. Exactly the odometer roll-over: run out of room, push one to the neighbour.
So adding a single column needs two answers, not one. There’s the sum bit — what stays in this column — and the carry — what spills into the next. Write the four cases out with both:
inputs sum bit carry
0 + 0 → 0 0
0 + 1 → 1 0
1 + 0 → 1 0
1 + 1 → 0 1
Two gates already give you both answers
Look at those two output columns on their own, and something lovely happens. You have already met circuits that produce exactly these patterns.
The carry is on only when both inputs are on. That is the AND gate from item 4 — on when this AND that.
The sum bit is on when the inputs are different — one on, one off — and off when they match. That pattern (on if the inputs differ) is called XOR, short for “exclusive or.” You can build it from the AND, OR and NOT gates you already know, but the easy way to hold it is just: XOR is on when its two inputs disagree.
So one column of addition is two gates side by side: an XOR feeding the sum bit, an AND feeding the carry. That tiny pairing has a name — the half-adder. Two switches in, two switches out, no understanding anywhere. The wiring is the arithmetic.
Chaining columns: the carry has to ripple
A half-adder is missing one thing. It adds two bits, but a real sum has a carry arriving from the column on its right too. The middle columns of any addition take three inputs: the two bits being added, plus the carry coming in.
Wire a circuit to add three bits — the two inputs and a carry-in — and produce a sum bit and a carry-out, and you have a full adder. (It’s just two half-adders stitched together, but you don’t need the wiring; you need the idea.) Now line one full adder up under each column of your numbers. Feed each column’s carry-out into the next column’s carry-in, left along the row. The carry ripples from right to left, column by column — which is precisely the carrying you learned to do by hand in item 2, now done by gates. A row of full adders like this is called a ripple-carry adder.
A worked example: 6 + 3, watched column by column
Take two four-bit numbers. We’ll add 0110 (that’s 4+2 = 6) and 0011 (that’s 2+1 = 3). Write the place values on top, the numbers below, and a carry row we’ll fill in as we go right to left:
value: 8 4 2 1
carry: 1 1 0 0 ← the carry coming into each column
A: 0 1 1 0 = 6
B: 0 0 1 1 = 3
─────────────────────
sum: 1 0 0 1 = 9
Walk it, rightmost column first, carry starting at 0:
- Column 1 (value 1): bits are 0 and 1, carry-in 0. Total 1. Sum bit 1, carry-out 0.
- Column 2 (value 2): bits 1 and 1, carry-in 0. Total 2 — that’s
10. Sum bit 0, carry-out 1. The carry spills left. - Column 4 (value 4): bits 1 and 0, plus the carry-in of 1. Total 2 again. Sum bit 0, carry-out 1. Another spill.
- Column 8 (value 8): bits 0 and 0, plus carry-in 1. Total 1. Sum bit 1, carry-out 0.
Read the sum bits top to bottom: 1001. Check it: 8 + 1 = 9. And 6 + 3 = 9. The gates got it right, and not one of them knew it was adding. You’ll drive this exact ripple yourself in the lab — set two numbers, then step the carry along.
No magic, only arrangement
That is the whole machinery of computer arithmetic. Every sum your computer does — totting up a bill, advancing a clock, finding a pixel’s place on screen, billions of times a second — is patient gates rippling carries from right to left. The same trick stretches further than addition: subtraction is addition with one number flipped, and multiplication is addition done many times over. The tower of maths your machine seems to “do” rests on this one move, repeated.
It’s worth sitting with how thin the cleverness is down here. There is no calculator-brain inside the chip, no spark of understanding — just switches, wired so their dumb on/off agreement happens to spell out a sum. What looks like intelligence is arrangement: simple parts, placed so the pattern that falls out the far side is the answer you wanted. We did the same thing to letters and colours a few lessons back. We are doing it now to arithmetic. Hold that, because the machine is about to start remembering what it computes — and memory is the same story told one layer up.
02 · Try · the lab
03 · Check · quick quiz
1. Adding one column of two bits, what makes 1 + 1 special compared with the other three cases?
- It needs two outputs: a sum bit of 0 in this column, and a carry of 1 to the next column left
- It is the only case the computer cannot work out
- It rounds up to the nearest whole number
- It produces a sum bit of 1 with no carry
Answer
It needs two outputs: a sum bit of 0 in this column, and a carry of 1 to the next column left — One plus one is two, which is '10' in binary — too big for one column. So the column shows a 0 and carries a 1 to the left. That's why a single column needs two outputs, the sum bit and the carry.
2. In a half-adder, the carry is on only when both inputs are on. Which gate produces that exact pattern?
- An OR gate
- An AND gate
- A NOT gate
- An XOR gate
Answer
An AND gate — AND is on only when both inputs are on — which is exactly when a column carries (1 + 1). The sum bit, on the other hand, is on when the inputs differ, which is the XOR pattern.
3. You add two binary numbers and the second-from-right column works out to 1 + 1 = 0 carry 1. What does that carry do?
- It is discarded, since each column is added on its own
- It is added into the very leftmost column
- It becomes the carry-in for the next column to the left, joining that column's own two bits
- It flips the sum bit in the same column to a 1
Answer
It becomes the carry-in for the next column to the left, joining that column's own two bits — The carry ripples one column to the left and is added in along with that column's two bits — a three-input sum. That left-to-right rippling is the same carrying you do by hand, just done by gates.
4. A computer adds millions of numbers a second and never makes a mistake. What is actually doing the adding?
- A built-in calculator chip that understands arithmetic
- Gates wired so their on/off output pattern equals the sum — no part of it understands maths
- A lookup table with every possible sum stored in advance
- The processor doing the maths the way a person reasons it out
Answer
Gates wired so their on/off output pattern equals the sum — no part of it understands maths — There is no understanding inside the chip. Addition is just gates arranged so the pattern that falls out equals the sum. Arithmetic is plumbing, not thinking — which is why it's both fast and never wrong.