Adding with Gates
XOR makes the sum, AND makes the carry, and a chain of them is the arithmetic heart of every processor.
Builds on: 7.1 Binary & Logic Gates
Counting in base two
With only 0 and 1 available, numbers use place values of 1, 2, 4, 8… instead of 1, 10, 100. Binary 1011 = 8 + 0 + 2 + 1 = 11. Four bits count 0–15, eight bits 0–255, and sixty-four bits count past the grains of sand on Earth. Same positional arithmetic you learned at age six — shorter alphabet.
One column of addition
Add two bits and what can happen? 0+0=0, 0+1=1, 1+1=0 carry 1. Look closely: the sum bit is exactly XOR, and the carry bit is exactly AND. Two gates — called a half adder — perform single-column addition. A real column must also accept the carry coming in from the right, so the full adder handles three inputs (A, B, carry-in) with two XORs plus a bit of AND/OR for the carry-out. About five gates per column, total.
Chain the columns
Stack one full adder per bit, wiring each carry-out to the next column’s carry-in, and you have a ripple-carry adder — the carry ripples leftward exactly like the “carry the one” of pencil arithmetic. If the final column produces a carry with nowhere to go, that’s overflow: the true answer needs more bits than you have. (Subtraction, multiplication, your GPU’s teraflops — all elaborations of this one circuit.)
Six lessons ago a transistor was a current amplifier. Wired into gates, gates into adders, the same silicon now does mathematics. No single part knows arithmetic — the knowledge lives entirely in the wiring. That is the whole magic of computers, and you now hold it end to end.
⚡ Lab — The 4-bit Adding Machine
Two 4-bit numbers, clickable bit by bit, summed by ripple-carry logic.
- Set A = 5 (0101) and B = 3 (0011). Follow each column: XOR for the sum, carries where both are 1.
- Set 15 + 1 and watch the carry ripple across every column into overflow.
- Verify: can any 4-bit + 4-bit sum ever need more than 5 bits?