A logic gate is a tiny rule that takes one or two bits in and gives exactly one bit out. Wire enough of them together and you get adders, memory and, in the end, a whole processor.
Why everything comes down to 0 and 1
Inside a chip, a bit is a voltage on a wire: low means 0, high means 1. Two levels are easy to tell apart even when the signal is a little noisy, which is why computers count in binary rather than in ten levels of voltage.
A gate is a small circuit, built from a handful of transistors, that reads the voltage on its input wires and sets the voltage on its output wire. It has no memory and no clock of its own. Change an input and the output follows a moment later.
Each gate is described by a truth table: every possible combination of inputs, and the output for each one. With two inputs there are only four rows, so you can learn a gate by learning its table.
The three basic gates
AND
AND outputs 1 only when both inputs are 1. A single 0 on either input makes the output 0.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Think of a door that needs a key card a PIN. Either one alone gets you nowhere.
Wondering how this was made? How we make these