How does a computer decide?
So far, with 0s and 1s, we've stored numbers and letters. But a computer doesn't just store things. It judges: yes or no. Let me show you where that judgment begins.
Two inputs, one output
Every judgment a computer makes
begins in one tiny part.
Its name is the logic gate.
It takes two switches as input,
and by a fixed rule
puts out a single on or off.
Try the three basic gates
with your own hands.
Toggle the switches on and off.
What you just touched
is the smallest unit of judgment
that makes up a computer.
Each of these little parts
turns on and off
by a fixed rule.
And, or, not
The three gates have different personalities.
AND is picky.
It turns on only if both are on.
OR is generous.
Even one being on turns it on.
NOT is contrary.
It flips whatever comes in.
AND · and
Like a safety guard that turns on only when you grip both handles at once, it turns on only if both are on.
OR · or
Like getting in whether the front or the back door is open, even one being on turns it on.
NOT · not
A contrarian that goes off when pressed and on when released. It flips the incoming signal.
The personalities of the three gates.
That's all, just these three.
Amazingly,
every judgment every computer makes
is built by mixing these three.
Put the cases in a table
A gate's rule
sums up neatly in one table.
Since the inputs are two ons and offs,
there are exactly four cases.
For each case, what the output is
is written down.
This is called a truth table.
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The truth table of the AND gate.
One look at the table makes it clear.
AND, on the last row alone,
only when both are on
does the output turn on.
Even judgments that looked complex
come down to a few tables like this.
Chain gates and they get smarter
One gate is simple,
but chain several together
and you can build far more complex judgments.
For example, a judgment that turns on
"only when the two inputs differ."
One gate can't do this,
but a few chained together can.
A combination that turns on only when they differ.
Stack simple gates like this,
piece by piece,
and you add numbers,
remember values,
and in the end you get a CPU.
Next time, with these very gates,
we'll build a machine that adds.