Module 5 · Adding With Light Switches

Which gates do you need to add one column?

Lesson 5.2 · Gates That Add

Jenny · Rob · Mark

The sum is XOR. The carry is AND.

Jenny writes out the four facts for one column and puts two answers beside each: the digit you write and whether you carry.

Rob spots it first. The digit you write is 1 when exactly one input is 1. That’s XOR. The carry is 1 only when both are 1.

That’s AND. Mark says that can’t be all there is. Jenny wires four columns and hands him the switches.

The short answer

XOR for the digit and AND for the carry, plus a little extra to take in a carry from the right. Chain them and you can add numbers as long as you have adders for. Mark had to admit that the laptop’s math really is just yes-or-no, a few billion times a second.

Try it yourself

Set both numbers on the switches and watch the gates add them, carries and all.

Set 1 + 1

1 of 3

First number

Second number

Carry

Off
Off
Off
Off

Sum

Off
Off
Off
Off
Off

0 + 0 = 0

What you just did has a name

An adder

An adder is a circuit made of gates that adds binary numbers.

A half adder adds two bits: XOR gives the sum, AND gives the carry.

A full adder also takes the carry from the column to its right.

Chain one full adder per bit, and the chain can add numbers as big as it has bits for. What happens past that is the next lesson.

Every processor has adders like this at its core.

A few more things

The carry ripples

Each column waits for the carry from the one on its right, so the answer ripples from right to left. Real chips use cleverer designs that look ahead at carries to go faster.

A few dozen transistors per column

A full adder needs roughly two dozen transistors, give or take. A 64-bit adder, the size modern processors use, is still only a tiny corner of a chip with billions.

Same parts, new job

Nothing new got invented here. XOR and AND from Module 4, wired cleverly, became arithmetic.

Go deeper

The longer version, if you want it.

Building the full adder

A full adder has three inputs: bit A, bit B and the carry coming in. Its sum is A XOR B XOR carry-in. Its carry-out is on when at least two of the three inputs are on, which you can build from two ANDs and an OR, borrowing the XOR you already made for the sum.

Put 64 of those in a row, each one’s carry-out feeding the next one’s carry-in, and you have a working 64-bit adder. Real processors use a faster carry trick, but the idea is the one Stibitz built on his kitchen table.

Quick check

In a half adder, which gate gives you the carry?

Let’s take it slower

Look at one column again. Write 1 when exactly one of the two bits is 1: that rule is XOR. Carry 1 when both bits are 1: that rule is AND. So two gates do one column. Then you line up a row of those, each passing its carry to the next, like a bucket brigade. That row is the adder.

More examples

1

5 + 2

0101 + 0010. No column ever has two 1s, so there are no carries. XOR in every column gives 0111, seven.

2

An odometer rolling over

When a car hits 9,999 miles, every wheel rolls back to zero and a 1 appears on the left. Adding 1 to 0111 in binary does the same thing: every 1 flips to 0 and the carry lands in a brand-new column, 1000.

Back to the question

So which gates add one column?

Show the answer

XOR for the digit and AND for the carry, plus a little extra to take in a carry from the right. Chain them and you can add numbers as long as you have adders for. Mark had to admit that the laptop’s math really is just yes-or-no, a few billion times a second.

One last question

Pick the three things that happen in one adding column.

Tap everything that fits, then check.

…
Talk Card

Talk Card · 5.2

An adder is built from gates: XOR gives each column’s digit, AND gives its carry, and the carry passes to the next column. Chain them and you can add numbers as long as you have adders for.

How Computers Work · pettigrewlab.com/learn

Next lesson