Computer Architecture
Half adder vs full adder
A half adder adds two bits, A and B, and gives a sum bit and a carry bit. A full adder adds three bits: A, B and a carry in from the column before. That third input is the whole difference, and it's what lets full adders chain together to add numbers of any width.
The half adder
Adding two bits has four cases. 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 2, which in binary is 10: a 0 in this column and a 1 carried to the next.
| A | B | SUM | CARRY |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The SUM column is exactly XOR's table, and the CARRY column is exactly AND's. So a half adder is two gates:
The full adder
In a long sum, every column except the first also has to add the carry from the column to its right. Three bits add to anything from 0 to 3, and 3 is 11 in binary, so one sum bit and one carry out still cover it:
The sum is 1 when an odd number of the three inputs are 1. The carry out is 1 when two or more are 1. The first AND catches A and B both being 1; the second catches a carry in meeting exactly one of them, the case a half adder's AND would miss.
Live experiment
One column of a sum, in gates
A full adder in five gates: two XORs make SUM, two ANDs and an OR make COUT. Set A, B and the carry in, CIN, on the three switches and watch every wire light by its level. Find the carry that A AND B alone can't make.
“Add two bits” is lesson 1 of 6 in Register Reef, Computer Architecture World 1. Free with an account. It’s open as soon as you sign up.
That's two half adders and an OR: the first adds A and B, the second adds the carry in to that sum, and the OR joins the two carries. Five gates in all.
Chaining them
To add two 4-bit numbers, line up four full adders, one per column. Each carry out feeds the next column's carry in, and the first column's carry in is tied to 0, which is why that column could be a half adder. This is a ripple-carry adder.
A carry out of the top column has nowhere to go: four bits hold 0 to 15, so 9 + 8 = 17 shows as 1. That lost carry is overflow, and a processor keeps it as its carry flag. Every adder in every computer, from a calculator to a graphics card, is built from columns like this one.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Add two bits” is lesson 1 of 6 in Register Reef, Computer Architecture World 1. Free with an account. It’s open as soon as you sign up.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: Two or more of A, B and CIN are 1. Three bits add to 2 or 3 only when at least two are 1, and 2 or 3 carries. (A AND B) catches A and B; ((A XOR B) AND CIN) catches one of them with the carry in.
- Why not “All three are 0”? All three at 0 add to 0: nothing to carry at all.
- Why not “Exactly one is 1”? Exactly one 1 adds to 1, which is a sum of 1 with no carry.
- Why not “A XOR B is 1”? A XOR B being 1 means exactly one of A and B is 1. That carries only if the carry in is 1 too, so on its own it isn't enough.
Show the answer
Answer: SUM 1, COUT 1: three ones is 11 in binary. 1 + 1 + 1 = 3, which is 11 in binary: a 1 in this column and a 1 carried to the next.
- Why not “SUM 0, COUT 1”? SUM 0 with a carry is 1 + 1 = 2. Three ones make 3, which is 11 in binary, so SUM is 1.
- Why not “SUM 1, COUT 0”? SUM 1 with no carry is just 1. Three ones make 3, which needs the carry as well.
- Why not “SUM 0, COUT 0”? Three ones add to 3, not 0, so at least one output has to be 1.
Show the answer
Answer: SUM 0, CARRY 1. 1 + 1 is 10 in binary, so the sum bit is 0 and the carry is 1. XOR of 1 and 1 is 0; AND of 1 and 1 is 1.
- Why not “SUM 1, CARRY 0”? SUM 1 and no carry is 1 + 0. With two 1s, the column overflows: 1 + 1 is 10 in binary.
- Why not “SUM 0, CARRY 0”? SUM 0 and CARRY 0 is 0, but 1 + 1 is 2, written 10: a 0 here and a 1 carried.
- Why not “SUM 1, CARRY 1”? SUM 1 and CARRY 1 is 3, which needs three 1s. A half adder only has two inputs.
“Add two bits” is lesson 1 of 6 in Register Reef, Computer Architecture World 1. Free with an account. It’s open as soon as you sign up.
Questions people ask
What is the difference between a half adder and a full adder?
A half adder adds two bits, A and B, and gives a sum and a carry out. A full adder adds three, A, B and a carry in from the column before. Only the full adder can be chained to add numbers wider than one bit.
How many gates are in a full adder?
Five in the usual design: two XORs for the sum, and two ANDs and an OR for the carry. It's two half adders, each an XOR and an AND, with an OR joining their carries.
What is a ripple-carry adder?
A row of full adders, one per bit, each passing its carry out to the next one's carry in. It's simple, but the top bit has to wait for a carry to ripple through every column, so wide ones are slow. Fast processors use carry-lookahead adders.
Related topics
- Binary numbers explainedPlaces worth 1, 2, 4 and 8: add up the bits that are on, and four wires count to 15.
- Logic gates explainedAND, OR, NOT, XOR and their bubbled twins: each one's rule is a truth table.
- Why is NAND called a universal gate?NOT, AND, OR and XOR from one kind of gate, and why chips love it.
- What is an ALU, and how does it work?Work out every answer at once, then let the opcode pick one: the heart of a CPU.