Computer Logic Gates
Logic gates are the tiny decision makers inside every processor. A gate receives one or more inputs, each either 0 or 1, and produces a single output by a fixed rule. Billions of gates working together run your phone, laptop, and game console. Think of a gate as a doorman who follows a strict rule, such as letting a guest in only when two conditions are true.
The Switch Idea
Electric switches model logic. Two switches wired in a row (series) behave like AND, because current flows only when both switches close. Two switches wired side by side (parallel) behave like OR, because current flows when either switch closes.
AND (series) OR (parallel)
──[A]──[B]──► Lamp ──┬─[A]─┬──► Lamp
Both must close └─[B]─┘
Either one may close
Basic Gates
NOT Gate
The NOT gate flips its single input. A 0 becomes 1, and a 1 becomes 0.
A | Output 0 | 1 1 | 0
AND Gate
The output equals 1 only when every input equals 1. A bank vault that opens with two keys follows this rule.
A B | Output 0 0 | 0 0 1 | 0 1 0 | 0 1 1 | 1
OR Gate
The output equals 1 when at least one input equals 1. A room with two doors works this way: opening either door lets you in.
A B | Output 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 1
Derived Gates
NAND and NOR
NAND is AND followed by NOT. NOR is OR followed by NOT. Engineers value them because any other gate can be built from NAND gates alone. Chip factories often use NAND as the main building block for that reason.
A B | NAND | NOR 0 0 | 1 | 1 0 1 | 1 | 0 1 0 | 1 | 0 1 1 | 0 | 0
XOR Gate
XOR means exclusive OR. The output equals 1 when the inputs differ. Two light switches at opposite ends of a hallway follow this idea: flipping either one changes the light.
A B | XOR 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0
Gate Symbols
AND: A ──┤ & ├── Out OR: A ──┤ ≥1 ├── Out
B ──┤ ├ B ──┤ ├
NOT: A ──►o── Out XOR: A ──┤ =1 ├── Out
B ──┤ ├
Building a Half Adder
Gates combine to perform math. A half adder adds two single bits. It uses an XOR gate for the sum and an AND gate for the carry.
┌─────── XOR ───────► Sum
A ──┬───┤
│ └─────── AND ───────► Carry
B ──┴───┘
A B | Sum Carry
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1 (1 + 1 = binary 10)
Chain many adders together and the processor adds numbers with dozens of bits. The ALU inside the CPU holds thousands of such circuits.
From Gates to Computers
Transistors → Logic Gates → Adders, Memory Cells → ALU, Registers → CPU
A transistor acts as a microscopic switch. Combining a few transistors produces one gate. Combining gates produces adders and memory cells. Combining those produces a processor.
Everyday Logic
- A phone unlocks when the passcode is correct AND the screen is on.
- An alarm rings when the door sensor OR the window sensor triggers.
- A search filter shows items that are NOT out of stock.
Combining Gates: A Door Alarm
A home alarm sounds when the system is armed AND either the door sensor OR the window sensor fires. Written as a rule: Alarm = Armed AND (Door OR Window).
Door ──┐
OR ──┐
Window ──┘ AND ──► Alarm
Armed ────────┘
Test a few cases. Armed with the door open gives an alarm. Disarmed with the door open stays silent. Armed with every sensor closed stays silent too.
Boolean Algebra
In the 1800s, mathematician George Boole created an algebra for true and false values. Engineers write gate behavior as short formulas. AND uses a dot, OR uses a plus sign, and NOT uses a bar above the letter. These formulas let designers simplify a circuit, which cuts the number of gates, the heat, and the cost.
Memory From Gates
Gates feed their outputs back into each other to remember a value. This loop, called a latch, holds one bit as long as power flows. Millions of latches form the fast memory cells inside a processor.
Key Takeaways
- Gates convert input bits into one output bit by a fixed rule.
- AND, OR, and NOT form the base set.
- NAND can build every other gate.
- Gates join to form adders, and adders form the ALU of a CPU.
