In the previous post, we built a half adder that performs single-digit binary addition using logic gates. But the half adder has one limitation. While the first digit only needs to consider two inputs, every subsequent digit must also handle the carry value from the previous digit.
Click the bits below to try two-digit binary addition yourself. You can see how the carry value is passed when calculating the twos place.
Units half adder
Twos full adder
A circuit that can handle all three input values (A, B, and the carry from the lower digit) is called a full adder.
The truth table for a full adder is as follows. To distinguish them, we call the carry from the previous digit Cin and the carry to the next digit Cout.
| Cout | Sum | |||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
It looks complex, but think of each row as binary addition. For example, the last row is 1 + 1 + 1 = 11₂, so Sum is 1 and Cout is 1.
A full adder can be built using half adders and an OR gate.
A single full adder can only handle 1-bit addition. So how do we add multi-digit numbers like 4-bit or 8-bit?
Since the method of addition doesn’t change just because the number of digits changes, we simply connect multiple full adders in sequence. Place one full adder at each digit position, and connect each Carry-out to the next digit’s Carry-in.
With 10 full adders, you can add numbers over 1,000; with 30, over a billion. The example below calculates 1112 + 12 = 10002.
This approach is called a ripple carry adder. It’s named so because the carry propagates from one digit to the next like a ripple.
For reference, not just addition but subtraction and multiplication can all be built from combinations of logic gates.
One problem remains. All the circuits we’ve built so far cannot remember their results. Once a calculation is done, the result vanishes. To become a real computer, it needs to be able to store and remember information.
For example, suppose you want to calculate the 1000th Fibonacci number. The Fibonacci sequence builds each value by adding the two before it, but if you can’t remember any previous results, you’d have to start from scratch every time. That’s extremely inefficient, and it makes building practical programs impossible.
In the next post, let’s solve this problem. We’ll build a circuit that stores information using logic gates and understand the basic principles of memory.