Textbooks/Digital Logic and Computer Architecture/Chapter 3
3Combinational building blocks
Version 1 · Technically checked (automated checks only) · 3 source lessons · 7 practice items
Introduction
Engineers rarely design with single gates. They reuse a small set of blocks: the adder that does arithmetic, the multiplexer that chooses between signals and the decoder that points at one of many outputs. This chapter builds each block from gates, and shows that the NAND gate on its own can make all of them.
Explanation
This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.
3.1 Everything from NAND
If you could only manufacture one kind of gate, could you still build a whole computer? Engineers found the answer is yes, twice.
NOT and AND
NOT A = NAND(A, A). A AND B = NOT(NAND(A, B)), which is two NANDs: one NAND, then a NAND with its inputs tied as a NOT.
OR via De Morgan
De Morgan says A + B = ¬(¬A · ¬B), which is NAND(¬A, ¬B). So OR takes three NANDs: two as NOTs on the inputs, and one to combine them.
XOR in four
Let g1 = NAND(A, B). Then g2 = NAND(A, g1), g3 = NAND(B, g1), and Y = NAND(g2, g3) = A ⊕ B. Check row 11: g1 = 0, g2 = 1, g3 = 1, Y = 0. Row 10: g1 = 1, g2 = 0, g3 = 1, Y = 1.
Why one gate type helps
A factory that makes one well-tested cell can tile it millions of times. Designers still use many gate types today, but the fact that NAND (or NOR) is universal shows how little you need to compute anything.
Common mix-ups
- Using only NAND gates always gives the smallest circuit.
✓ It is always possible, not always smallest. Real designs mix gate types for size and speed.
3.2 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?
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.
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.
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.
3.3 Multiplexers and decoders: choosing and pointing
A robot has eight sensors but only one analog-to-digital converter. How does it read them all through one input?
Multiplexer: a selector
A 2:1 multiplexer has data inputs A and B and a select input S. If S = 0 the output copies A; if S = 1 it copies B: Y = ¬S·A + S·B. A 4:1 mux uses two select bits; an 8:1 mux uses three.
Decoder: a pointer
A decoder takes an n-bit number and switches on exactly one of 2ⁿ outputs. A 2-to-4 decoder with inputs A1 A0 has outputs D0 = ¬A1·¬A0, D1 = ¬A1·A0, D2 = A1·¬A0, D3 = A1·A0. Give it 10 and only D2 lights.
Where machines use them
A microcontroller uses a mux to connect one of its many analog pins to its single converter. Memory uses decoders to switch on one row out of thousands. A processor uses muxes to choose which register feeds the adder.
Common mix-ups
- A multiplexer mixes its inputs together.
✓ It passes exactly one input through, chosen by the select lines.
Open the full lesson: Multiplexers and decoders: choosing and pointing →
Worked examples
Everything from NAND: example 1
Show that NAND(NAND(A, A), NAND(B, B)) is A OR B.
Solution
NAND(A, A) = ¬A and NAND(B, B) = ¬B. NAND(¬A, ¬B) = ¬(¬A · ¬B) = A + B by De Morgan. Three NANDs make OR.
Half adders and full adders: example 1
Use the full adder equations for A = 1, B = 0, Cin = 1.
Solution
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.
Multiplexers and decoders: choosing and pointing: example 1
A 2:1 mux has A = 0, B = 1, S = 1. What is Y?
Solution
Y = ¬S·A + S·B = 0·0 + 1·1 = 1: S = 1 selects B.
Interactive figures
Interactive figure (online). Description: 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.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Silicon Studio stage
Silicon Studio: Half adders
Build a half adder and confirm all four rows of its table.
Open Silicon Studio: Half adders →Silicon Studio stage
Silicon Studio: Full adders
Chain two half adders and an OR gate into a full adder, then test the 1 + 1 + 1 case.
Open Silicon Studio: Full adders →Silicon Studio stage
Silicon Studio: Multiplexers
Use a 4-to-1 multiplexer to choose a sensor, and count how many select lines it needs.
Open Silicon Studio: Multiplexers →BUILD level
BUILD: Virtual computer, Level 2
Find where the build's datapath uses an adder and a multiplexer, and say what each one decides.
Open BUILD: Virtual computer, Level 2 →
Guided practice
Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.
- How do you make NOT from a single NAND?
- Connect one input to 0
- Connect both inputs to the signal
- Connect one input to the output
- How many NAND gates does the classic XOR construction use? (gates)
- A half adder is built from…
- Two ANDs
- An XOR for the sum and an AND for the carry
- An OR for the sum and a NOT for the carry
- For a full adder with A = 1, B = 1, Cin = 1, read Cout S as a 2-bit binary number. What is its value in decimal?
- How many full adders does an 8-bit ripple-carry adder use (one per column)? (adders)
- In a 2:1 multiplexer Y = ¬S·A + S·B, what does S = 0 do?
- Outputs B
- Outputs A
- Outputs A AND B
- How many select lines does a multiplexer need to choose one of 16 inputs? (lines)
Engineering applications
Arithmetic units
Every processor's arithmetic logic unit contains adders built from the full adder in this chapter, with multiplexers choosing which result reaches the output.
Memory addressing
A decoder turns an address into exactly one active line, so one row of a memory responds. A 3-to-8 decoder picks one of 2^3 = 8 rows.
Watch
Optional verified videos. Nothing loads from YouTube until you press play.
- How a transistor works (Ben Eater)
- How Computers Calculate - the ALU: Crash Course Computer Science #5 (CrashCourse)
Chapter summary
- NAND is universal: NOT, AND, OR and XOR can all be built from NAND gates alone.
- A half adder adds two bits: sum = A XOR B, carry = A AND B.
- A full adder also accepts a carry in, so full adders can be chained to add longer numbers.
- A multiplexer with k select lines chooses one of 2^k inputs; a decoder with k inputs activates one of 2^k outputs.
Glossary
- NAND and NOR (universal gates)
- NAND outputs 0 only when all inputs are 1; NOR outputs 1 only when all inputs are 0. Either one alone can build every other logic function.
- Half adder
- A half adder adds two single bits and gives a sum bit (A XOR B) and a carry bit (A AND B).
- Full adder and ripple-carry adder
- A full adder adds three bits (A, B and a carry in) to give a sum and a carry out. Chaining n of them, each carry out feeding the next carry in, makes an n-bit ripple-carry adder.
- Multiplexer
- A multiplexer passes one of several data inputs to a single output, chosen by a binary number on its select lines; 2^k inputs need k select lines.
- XOR gate
- An XOR gate outputs 1 when its inputs are different and 0 when they are the same.
Definitions from the Field Guide.
Project: An all-NAND selector
Design a 2-to-1 multiplexer (output A when S = 0, B when S = 1) using only NAND gates. Count the gates, then check your design against the truth table for all eight input combinations.
Deliverables
- A gate diagram using only NAND
- The gate count
- An eight-row truth table check
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- David Money Harris and Sarah L. Harris (2012). Digital Design and Computer Architecture, 2nd edition. Morgan Kaufmann.
- Noam Nisan and Shimon Schocken (2021). The Elements of Computing Systems: Building a Modern Computer from First Principles, 2nd edition. MIT Press. Link ↗
Publication record
- Version
- 1
- Status
- Technically checked (automated checks only)
- Technical review
- Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
- Written by
- Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
- Licence
- All rights reserved by the founders unless a licence is approved.
- Corrections
- None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.