Lesson 3 of 5
Logic Gates: Build a Full Adder
Go from single transistors to a circuit that can actually add — with truth tables you have to complete yourself.
Learn it
Every calculation your computer performs is built from three simple gates: AND, OR and NOT.
Combine an XOR and an AND gate and you get a half adder — a circuit that adds two bits and produces a sum and a carry.
Chain full adders together and you have the arithmetic unit at the heart of the ALU.
Key terms
- XOR
- Exclusive OR — outputs 1 when exactly one input is 1.
- Half adder
- Circuit adding two bits, producing a sum and a carry-out, with no carry-in.
- Full adder
- Circuit adding two bits plus a carry-in, producing a sum and a carry-out.
- Propagation delay
- Time taken for a change at a gate's input to appear at its output; it accumulates through a circuit.
A full adder in code
pythondef full_adder(a, b, cin):
s1 = a ^ b
total = s1 ^ cin
cout = (a & b) | (cin & s1)
return total, cout
carry = 0
result = []
for a, b in zip('1011'[::-1], '0111'[::-1]): # 11 + 7
bit, carry = full_adder(int(a), int(b), carry)
result.append(str(bit))
print(''.join(reversed(result)), 'carry', carry)This is a ripple-carry adder: the carry from each column feeds the next, exactly like the hardware.
Try it
Decide which statements about gates and adders are true.
For a full adder, inputs A=1, B=1, Cin=1 give Sum=1 and Cout=1.
A half adder can be cascaded to add multi-bit numbers on its own.
NAND is functionally complete — any circuit can be built from NAND gates alone.
A 32-bit ripple-carry adder is as fast as a 4-bit one.
A XOR B equals (A OR B) AND NOT (A AND B).
Challenge
On paper, draw a 4-bit ripple-carry adder from full adders, then extend it into an adder/subtractor by adding XOR gates on one input and feeding the control line into Cin. Explain why that single control line turns addition into two's complement subtraction.
Pick whichever way suits you — every mode earns the same bonus XP.
Write at least 40 more characters to submit.
Mark your own work
Guided walkthrough — 0/5 clues revealed
- Clue 1 locked — reveal it only if you get stuck.
- Clue 2 locked — reveal it only if you get stuck.
- Clue 3 locked — reveal it only if you get stuck.
- Clue 4 locked — reveal it only if you get stuck.
- Clue 5 locked — reveal it only if you get stuck.
Each clue costs 7 XP (never below 33 XP). You'd earn 65 XP right now.
Extension: Estimate the propagation delay in gate-delays for your 4-bit adder and compare with an 8-bit version.