Lite / Building Machines That Respond / Week 15
Logic gates and truth tables
Every decision your phone makes, from unlocking to sending a message, comes down to a few kinds of tiny switch. How few kinds?
Why should I care?
This lesson opens the computer architecture thread. A processor is built from billions of gates, but there are only a handful of kinds. Learn their rules now and you can follow a signal all the way from a switch to an adder, and later to a whole CPU.
- Write the truth tables of NOT, AND, OR, NAND, NOR and XOR.
- Explain that a truth table with n inputs has 2ⁿ rows and describes a gate completely.
- Connect a logic level to a voltage and a gate to transistors made of doped silicon.
Predict
A truth table lists the output for every possible combination of inputs. How many rows does a gate with three inputs need?
- 3
- 6
- 8
- 9
Guess first, then reveal
Each input can be 0 or 1, so three inputs give 2 × 2 × 2 = 8 combinations: 000 up to 111. In general n inputs need 2ⁿ rows.
Discover
In the logic lab, start from the 'One gate' preset. Change the gate to each type in turn (AND, OR, NAND, NOR, XOR) and toggle A and B through all four combinations. Copy each live truth table into your notebook. Which two gates are exact opposites of each other?
What the interactive shows (text version)
In the logic lab's one-gate preset, toggling inputs A and B through 00, 01, 10 and 11 gives: AND 0,0,0,1; OR 0,1,1,1; NAND 1,1,1,0; NOR 1,0,0,0; XOR 0,1,1,0. OR and NOR are exact opposites, as are AND and NAND.
Watch (optional)
Watch for: Notice how each gate is first built from transistors acting as switches, before it becomes a symbol.
Introduces AND, OR, NOT and XOR, the building blocks behind every digital decision a computer makes.
“Boolean Logic & Logic Gates: Crash Course Computer Science #3” 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
Bits as voltages
Digital circuits treat a voltage near the supply (say 3.3 V or 5 V) as 1 and near 0 V as 0. Anything in between is avoided. Because only two levels matter, small amounts of noise do not change the answer.
The basic gates
NOT flips its input. AND gives 1 only if all inputs are 1. OR gives 1 if any input is 1. XOR gives 1 if the inputs differ. NAND and NOR are AND and OR followed by NOT. Engineers write them as ¬A, A·B, A + B and A ⊕ B.
A truth table says everything
List every input combination in counting order (00, 01, 10, 11) and write the output. That table completely defines the gate: two circuits with the same truth table do the same job, however different they look.
Gates are made of transistors
A transistor is a switch made from doped silicon (week 10): a voltage on one terminal lets current flow between the other two. Two transistors in series make a NAND-like path; in parallel, a NOR-like one. That is how a material property becomes logic.
Explain it another way
Intuitive
AND is two light switches in series: both must be on. OR is two switches in parallel: either will do. NOT is a switch that is on when you are not pressing it.
Technical
Boolean functions map {0,1}ⁿ to {0,1}. Logic families such as CMOS implement them with complementary transistor networks so that the output is always driven firmly to one rail or the other.
Mathematical
There are 2ⁿ input rows, and each row's output can be 0 or 1, so there are 2^(2ⁿ) different n-input functions: 16 for two inputs, 256 for three.
Applied
A car's interior light comes on if the driver's door OR the passenger's door is open. A lift moves only if the doors are closed AND a floor is selected. Logic gates make these rules physical and fast.
Worked example 1
Write the truth table of A NAND B.
AND gives 0, 0, 0, 1 for AB = 00, 01, 10, 11. NOT flips each: NAND = 1, 1, 1, 0. It is 0 only when both inputs are 1.
Common mix-ups
OR means one or the other but not both.
✓ In logic, OR includes the case where both are 1. 'One but not both' is XOR.Logic 1 always means exactly 5 V.
✓ It means 'near the high supply rail', which might be 5 V, 3.3 V or 1.8 V depending on the chip.
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
Choose a machine at home or school (a microwave, a lift, a printer). Write three of its rules as gates, for example 'heat only if door closed AND timer running'. For one rule, write the full truth table and test it in the logic lab.
Reflect
Why is it useful that a truth table describes a gate completely, whatever is inside it?
Write your answer on paper or in your own notes. Lite never stores what you write.