A slide show about the tiny switches inside every computer. Use the buttons, the ← → arrow keys, or swipe on a touch screen to move between slides.
Computer Logic Gates The building blocks of every digital computer AND OR NOT XOR
What Is a Logic Gate? • An electronic circuit that takes one or more binary inputs and produces a single binary output A • Binary signals have only two states: 1 (HIGH, Q true, voltage on) and 0 (LOW, false, voltage off) B • Each gate implements a Boolean function — rules from Boolean algebra (George Boole, 1854) Inputs (A, B) on the left, output (Q) on the right • Built from transistors acting as tiny electronic switches • Combined in their billions to build processors, memory and more
Binary Signals and Truth Tables • A truth table lists the output for every possible combination of inputs A B Q • With n inputs there are 2ⁿ combinations — 0 0 ? 2 inputs give 4 rows 0 1 ? • Boolean expressions describe the same 1 0 ? behaviour in algebraic form 1 1 ? • Notation used here: · = AND, + = OR, ⊕ = Every 2-input gate fills in this XOR, overbar = NOT column differently • Green cells in the tables show where the output is 1
The Seven Basic Logic Gates AND OR NOT NAND NOR XOR XNOR
AND Gate A B Q A 0 0 0 Q B 0 1 0 1 0 0 1 1 1 Q=A·B • Output is 1 only when ALL inputs are 1 • Like two switches in series — both must be closed for the lamp to light • Used for: enabling signals, masking bits, checking that several conditions hold
OR Gate A B Q A 0 0 0 Q B 0 1 1 1 0 1 1 1 1 Q=A+B • Output is 1 when AT LEAST ONE input is 1 • Like two switches in parallel — either one can light the lamp • Used for: combining alarm/interrupt signals, setting bits
NOT Gate (Inverter) A Q 0 1 A Q 1 0 Q=A • Has only ONE input • Output is the opposite of the input: 0 becomes 1, 1 becomes 0 • The small circle (bubble) on any gate symbol means "invert"
NAND Gate (NOT AND) A B Q A 0 0 1 Q B 0 1 1 1 0 1 1 1 0 Q=A·B • An AND gate followed by a NOT • Output is 0 only when ALL inputs are 1 • A universal gate — any other gate can be built from NANDs alone • The cheapest gate to make in CMOS — the workhorse of chip design
NOR Gate (NOT OR) A B Q A 0 0 1 Q B 0 1 0 1 0 0 1 1 0 Q=A+B • An OR gate followed by a NOT • Output is 1 only when ALL inputs are 0 • Also a universal gate • The Apollo Guidance Computer was built entirely from NOR gates
XOR Gate (Exclusive OR) A B Q A 0 0 0 Q B 0 1 1 1 0 1 1 1 0 Q = A ⊕B • Output is 1 when the inputs are DIFFERENT • "One or the other, but not both" • Used for: binary addition, parity checks, simple encryption, comparing bits
XNOR Gate (Exclusive NOR) A B Q A 0 0 1 Q B 0 1 0 1 0 0 1 1 1 Q = A ⊕B • Output is 1 when the inputs are the SAME • Also called the equality gate • Used for: comparators that test whether two binary numbers are equal
Universal Gates: NAND and NOR • NAND and NOR are called universal gates NOT gate made from a NAND • Any Boolean function can be built using only one of them • NOT: tie both NAND inputs together (see diagram) A A • AND: a NAND followed by a NAND-as-NOT • OR: invert each input with a NAND, then NAND the results (De Morgan's law) • Manufacturers can optimise a single gate type and build everything else from it De Morgan's Laws A·B=A+B A+B=A·B
Combining Gates: The Half Adder A B S C A 0 0 0 0 Sum (S) B 0 1 1 0 1 0 1 0 1 1 0 1 S = A ⊕B Carry (C) C=A·B 1 + 1 = 10 (binary) • Adds two single bits using just one XOR and one AND gate • Chaining full adders (two half adders + an OR) lets a CPU add numbers of any width
How Gates Are Built: Transistors • Modern gates use CMOS transistors — tiny voltage-controlled switches • A NAND or NOR gate needs just 4 transistors; NOT needs only 2 • A modern CPU contains tens of billions of transistors forming billions of gates • Each gate switches in a few picoseconds, enabling clock speeds of several GHz • History: relays (1930s) → vacuum tubes (1940s) → discrete transistors (1950s) → integrated circuits (1960s onward)
Where Logic Gates Are Used Arithmetic Memory Control Adders, subtractors and Latches and flip-flops Decoders and multipliers inside the store bits using gates multiplexers route data CPU's ALU with feedback and select instructions Error checking Security Everyday devices XOR-based parity bits XOR is at the heart of Washing machines, and checksums detect many encryption traffic lights, alarms and corrupted data algorithms calculators
Summary Gate Expression Output is 1 when... AND A·B all inputs are 1 OR A+B at least one input is 1 NOT A the input is 0 NAND A·B not all inputs are 1 NOR A+B all inputs are 0 XOR A ⊕B inputs are different XNOR A ⊕B inputs are the same