Chapter 3

Logic Gates

You just watched two transistors turn into an AND and an OR. From here on, we'll stop drawing individual transistors and start treating each wired-up bundle as a single box called a logic gate — each one follows one dead-simple rule about its inputs. Click the switches below and watch each one think.

NOT — "give me the opposite"

The simplest gate of all. One input, one output. Whatever comes in, the opposite comes out.

AOUT
01
10

AND — "only if both"

Output is 1 only when every input is 1. Think of two switches wired in a row — current only completes the loop if both are closed.

ABOUT
000
010
100
111

OR — "if either one"

Output is 1 if at least one input is 1. Like two switches wired side by side — either one closing completes the loop.

ABOUT
000
011
101
111

XOR — "if different"

"Exclusive OR." Output is 1 only when the inputs disagree. Two matching inputs (0,0 or 1,1) give 0. Remember this one — it's about to become the star of the show.

ABOUT
000
011
101
110

Under the hood: a NOT gate takes about 2 transistors, an AND or OR gate about 6, and an XOR gate around 8–12. A modern chip strings together billions of these — but every single one of them is just one of these four simple rules.

Coming up: a switch only ever means 0 or 1 — so how does a computer represent a number like "37"? Next: binary numbers.