seegongsik
Structure

How do logic gates work

So far we've stored numbers and text in 0s and 1s. But a computer doesn't just store things; it also decides "yes" or "no." In this lesson we follow where those decisions begin.

01

Two inputs, one output

Every decision a computer makes starts with a tiny part called a logic gate.
A gate takes switches as input and, following a fixed rule, puts out a single on or off.
Below you can switch the three basic gates on and off yourself.
The name "gate" comes from the way it lets a signal through or blocks it, like a door.

0
0
AND
0
It turns on only if both are on

Switch the inputs on and off and each gate's output changes right away.

What you just played with is the smallest unit of decision in a computer.
All these parts do is turn on and off into on and off by a fixed rule.
The rule never changes and never gets tired, so the same input always gives the same answer.

02

AND, OR, NOT

The three gates each have their own personality.
AND is picky: it turns on only when both inputs are on.
OR is easygoing: one input being on is enough.
NOT is contrary: it flips whatever comes in.
And unlike the other two, NOT takes only one input.

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.

How the three gates treat their inputs.

There are only these three basic gates.
Amazingly, every decision made by every computer in the world is built by mixing them.
However many conditions a decision has, it's still a combination of "yes" and "no," so these three are enough to express all of it.

03

All the cases in one table

A gate's rule fits neatly into one table.
With two inputs that are each on or off, there are exactly four possible cases, and you just write down the output for each one.
This table is called a truth table.
Every extra input doubles the number of cases, so three inputs mean eight rows and four inputs mean sixteen.

Input AInput BOutput
000
010
100
111

The truth table for the AND gate.

The table makes the rule clear at a glance.
For AND, the output is on only in the last row, where both inputs are on.
The OR table is the reverse case: only the first row, with both inputs off, is off, and the other three rows are on.
Even decisions that look complicated come down to a few tables like this.

04

Wire gates together and they get smarter

One gate is simple, but chain several together and you can build far more complex decisions.
A good example is a decision that turns on only when the two inputs are different.
One gate can't do it, but a few wired together can.
This "are they different?" check is exactly the piece used to compare two values and to add them.

0
0
Are they different?
0
They are the same, so it stays off

A combination that turns on only when the inputs differ.

Stack these simple gates up, and you get circuits that add numbers and remember values, and finally a CPU.
In the next lesson we'll build an adding machine from these very gates.
The amazing part is that from here on, no new parts are needed.
All that changes is how many of the same three gates you use and how you wire them.

In one lineEvery decision a computer makes started from just three gates: AND, OR, and NOT. Wire these tiny parts together and you can build all of calculation and memory.
← Structure
Was this helpful? Support seegongsik