Lite / Building Machines That Respond / Week 16
Half adders and full adders
In binary, 1 + 1 = 10. A computer does that with two gates. How many does it need to add 1 + 1 + 1?
Why should I care?
The adder is the heart of a processor's arithmetic logic unit. Once you can add one column of bits with gates, you can add numbers of any size, and from there subtract, count and address memory.
- Write the truth tables of a half adder and a full adder.
- Derive S = A ⊕ B ⊕ Cin and Cout = A·B + Cin·(A ⊕ B).
- Explain how full adders chain to add multi-bit numbers.
Predict
Adding one column of binary, the inputs are A = 1, B = 1 and a carry in of 1. What do you write, and what do you carry?
- Write 0, carry 1
- Write 1, carry 1
- Write 1, carry 0
- Write 0, carry 0
Guess first, then reveal
1 + 1 + 1 = 3, which is 11 in binary: write 1 and carry 1. That row is the reason a full adder needs a carry input as well as a carry output.
Discover
Set 4 bits. Make A = 0001 and B = 0001 and step: the first column is a half adder. Now try A = 0111, B = 0001 and watch the carry ripple through three columns. Then turn on carry in. Fill in the eight-row full adder table in your notebook from what you see.
What the interactive shows (text version)
The adder stepper shows two 4-bit numbers as rows of bit buttons and reveals one column at a time from the right, giving each column's carry in, sum and carry out. Adding 0111 and 0001, the carry ripples through three columns to give 1000. The full adder table for A B Cin from 000 to 111 is Cout S = 00, 01, 01, 10, 01, 10, 10, 11.
Watch (optional)
Watch for: Watch the half adder being drawn from an XOR and an AND, then two half adders and an OR becoming a full adder.
Builds half and full adders from gates, chains them into a ripple-carry adder and explains overflow.
“How Computers Calculate - the ALU: Crash Course Computer Science #5” by CrashCourse (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Column addition in binary
Binary adds like decimal, with only two digits: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), 1 + 1 + 1 = 11 (write 1, carry 1).
The full adder table
For A B Cin = 000, 001, 010, 011, 100, 101, 110, 111, the outputs Cout S are 00, 01, 01, 10, 01, 10, 10, 11. In other words, Cout S is just the count of 1s written in binary.
Chaining adders
To add 4-bit numbers, line up four full adders, one per column. Each carry out feeds the next column's carry in, so the carry ripples from right to left. Next week you will add multi-bit numbers this way and see what happens when the answer is too big.
Explain it another way
Intuitive
A full adder counts how many of its three inputs are 1 and writes that count in binary: the right digit is the sum, the left digit is the carry.
Technical
A full adder is a 3-input, 2-output combinational block. Sum is the odd-parity function of its inputs; carry is the majority function (you simplified it in week 15: A·B + A·Cin + B·Cin, equivalent to A·B + Cin·(A ⊕ B)).
Mathematical
Check row 111: S = 1 ⊕ 1 ⊕ 1 = 1; Cout = 1·1 + 1·(1 ⊕ 1) = 1 + 0 = 1. Cout S = 11 = 3 = 1 + 1 + 1. ✓
Applied
Every addition your phone does, and every address it calculates in memory, passes through adders built from exactly these equations, usually with faster carry tricks layered on top.
Derivation: Building the full adder
Half adder (two inputs): the sum is 1 when exactly one input is 1, so S = A ⊕ B; the carry is 1 only when both are 1, so C = A · B.
Full adder (three inputs A, B, Cin): the column total A + B + Cin is 0, 1, 2 or 3, written as two bits Cout S.
S is 1 when the total is odd (1 or 3), which is when an odd number of inputs are 1: S = A ⊕ B ⊕ Cin.
Cout is 1 when the total is 2 or 3. Either A and B are both 1 (A·B), or exactly one of them is 1 and there is a carry in (Cin·(A ⊕ B)). So Cout = A·B + Cin·(A ⊕ B).
This is two half adders and an OR: the first adds A and B, the second adds Cin to that sum, and either carry makes Cout.
Worked example 1
Use the full adder equations for A = 1, B = 0, Cin = 1.
A ⊕ B = 1. S = 1 ⊕ 1 = 0. Cout = A·B + Cin·(A ⊕ B) = 0 + 1·1 = 1. Cout S = 10 = 2, and indeed 1 + 0 + 1 = 2.
Common mix-ups
A half adder is half as accurate as a full adder.
✓ It is exact, but it adds only two bits; the full adder also takes a carry in.Binary 1 + 1 = 2.
✓ 2 is not a binary digit: 1 + 1 = 10, write 0 and carry 1.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Build a full adder in the logic lab (the 'Full adder' preset is a model answer, so try it from scratch first) and check all eight rows against your table. Then explain in two sentences why the carry out is the majority function from week 15.
Reflect
How does knowing that a full adder 'counts its 1s' make its truth table easier to remember?
Write your answer on paper or in your own notes. Lite never stores what you write.