skill
Logic gates
Circuits that answer yes or no: highs and lows, truth tables, and NAND as the universal gate.
first shows up at Level 6 · Logic
A logic gate is a circuit with one job: look at its inputs, decide yes or no, and set its output accordingly. It only uses two voltages, high (near the + supply, call it 1) and low (near 0 V, call it 0). Everything a computer does is built from gates making these decisions billions of times a second.
The basic questions
- AND — output 1 only if every input is 1.
- OR — output 1 if any input is 1.
- NOT — output the opposite of the input.
- NAND — NOT-AND: output 0 only if every input is 1, otherwise 1.
The table of every input combination and its answer is the gate's truth table. A two-input NAND has four rows, and only the 1, 1 row gives 0.
Why NAND is special
Tie a NAND's two inputs together and it becomes a NOT. Put that NOT after a NAND and you have an AND. NAND the outputs of two NOTs and you have an OR. Every logic function can be built from NAND gates alone, which is why NAND is called universal and why a quad-NAND chip like the CD4011 is the first logic chip worth owning.
Reading an input
A CMOS gate compares each input with about half its supply: on 4.5 V, anything above 2.25 V is a 1 and anything below is a 0. The input draws essentially no current, so a 100 kΩ pull-down to − makes it a firm 0 and a button to + makes it a firm 1. An input connected to nothing is neither, and the chip misbehaves, so every input, used or spare, gets tied somewhere.
What an output can do
Gate outputs are signals, not power. A CD4011 output manages a milliamp or so at 5 V, enough for a dim LED through 220 Ω; for anything heavier it drives a transistor or a MOSFET gate. The Two-Key Lock wires two NANDs into an AND and lights an LED only when both buttons are down.