Part 04 / 12

What Is a Logic Gate?

A logic gate is a tiny decision-maker with one or more inputs, one output and a rule it never breaks, and seven of them, each with its own symbol and truth table, are enough to build a computer.

7 sections 1 interactive
§ 4.1

A tiny decision-maker

A microwave oven will not start with its door open. Somewhere inside, a circuit is following a rule: run the oven only if the door is closed and the start button has been pressed. Nobody has to think about it. Two signals come in, one goes out, and the rule decides.

That is a : a small circuit with one or more inputs, exactly one output, and a fixed rule that links them. It has no memory and no judgement. Give it the same inputs and it gives the same output, every time, within a few billionths of a second.

Each kind of gate has its own rule, and there are only a handful of kinds. The surprising thing, and the reason this series exists, is how far those few rules go. Wire gates to gates and you can compare numbers, add them, choose between signals, and, with a little feedback, remember. Every processor ever made is a very large number of gates following very simple rules.

§ 4.2

Only 1 and 0

A gate’s inputs and output are never “a bit high” or “fairly low”. Each one is either high, close to 5 volts, or low, close to 0 volts, and nothing in between counts. Those two states have several names, all meaning the same:

High Low
1 0
about 5 V about 0 V
true, yes, on false, no, off

Why only two? Because two states are easy to tell apart, even when the voltages are not perfect. Part 3 showed the margins: anything above 3.5 volts is high, anything below 1.5 is low. A signal can lose half a volt along a wire, or pick up a little noise, and still mean exactly what it meant. A circuit with ten different levels would need ten narrow bands, and every bit of noise would cause mistakes.

Because each input has only two possible values, you can list every possible situation. That list, with the output for each, is a . One input gives two rows. Two inputs give four: 00, 01, 10, 11, counted in binary, the same order every time. Three inputs give eight. Each extra input doubles the rows.

§ 4.3 · interactive

Try it: the seven gates

Try it

The seven gates

Choose a gate. Click A and B to switch the inputs between 0 and 1, or click a row of the truth table. The row that matches the inputs lights up.

Y = 0
ABY
00
01
10
11
Rule

The output is high only when A and B are both high.

In everyday life

A microwave runs only if the door is closed AND start is pressed.

Algebra

Y = A · B

On a chip

74HC08, four AND gates

IEC symbol &

AND: A = 0, B = 0 → Y = 0

The symbols are the distinctive shapes used on most datasheets. The IEC rectangle for each gate is shown below it.

§ 4.4

NOT, AND and OR

Three gates are the basic ones, and you have met their rules in ordinary speech.

NOT, also called an , has one input, and its output is always the opposite. Its symbol is a triangle, pointing the way the signal travels, with a small circle on the tip. That little circle, the bubble, always means “invert”, wherever you see it. A fridge light is a NOT gate: when the closed door presses its switch, the light is off; when the door opens and the switch is released, it comes on.

AND has two or more inputs, and its output is high only when all of them are high. Its symbol is a D shape with a flat back. A microwave’s start rule is an AND, and so are the two buttons on some industrial presses that must both be held, so that both of the operator’s hands are safely out of the way.

OR gives a high output when any input is high, including when they all are. Its symbol is a curved shield shape. A car’s ceiling light uses OR: it comes on if the driver’s door or the passenger’s door is open, or both.

§ 4.5

NAND, NOR, XOR and XNOR

Put a bubble on the output of AND and you get NAND, short for NOT AND: its output is low only when both inputs are high. A bubble on OR gives NOR, NOT OR: high only when neither input is high. These two look like afterthoughts, but they are the most important gates of all. Part 5 shows that a NAND is simpler to build than an AND, and part 9 that a NAND can build every other gate. Your 74HC00 holds four of them.

XOR, exclusive OR, is an OR with an extra curved line across its back. Its output is high when the two inputs are different: one or the other, but not both. Flip either input and the output changes, which is exactly how a stair light with a switch at the top and bottom behaves. XOR is also the heart of binary addition, as the last part of the series shows. XNOR adds a bubble, and its output is high when the inputs are the same.

Here are all seven in one table, the truth table you will come back to most:

A B NOT A AND OR NAND NOR XOR XNOR
0 0 1 0 0 1 1 0 1
0 1 1 0 1 1 0 1 0
1 0 0 0 1 1 0 1 0
1 1 0 1 1 0 0 0 1

AND, OR, NAND and NOR also come with three, four or more inputs, such as the 74HC11 with three-input ANDs. The rule stays the same: AND needs every input high, OR needs any one.

§ 4.6

Two ways to draw a gate

There are two standard sets of symbols, and you will meet both. The distinctive shapes, used in this series and on most datasheets, give every gate its own outline. They come from an American military standard and are now set out in IEEE Std 91. The rectangles of the international standard IEC 60617 draw every gate as the same box with a sign inside: & for AND, ≥1 for OR (“at least one input high”), =1 for XOR (“exactly one”), and 1 for a plain buffer. Many European schoolbooks use the rectangles.

The ideas are older than the electronics. In 1886 the American philosopher Charles Sanders Peirce wrote in a letter that logical operations could be carried out by electrical switching circuits. In 1924 the German physicist Walther Bothe built a coincidence circuit that signalled only when two particle detectors fired together, an early electronic AND gate, and it formed part of his share of the 1954 Nobel Prize in Physics.

§ 4.7

Build it: your first real gate

The circuit from part 3 had a gate with its two inputs joined, so it could only copy one button. Give each input its own button and pull-down, and the same chip makes a real decision.

  1. Fit the 74HC08 with pin 1 in f14, power it (a14 to +, j20 to −), add the 100 nF capacitor across the top rails, and tie pins 4, 5, 9, 10, 12 and 13 to − as in part 3.
  2. Button A across the channel in columns 3 and 5. Wire a3 to the + rail, fit a 10 kΩ from j5 to the − rail, and run a yellow wire from h5 to h14, pin 1.
  3. Button B in columns 8 and 10. Wire a8 to +, fit a 10 kΩ from j10 to −, and run a green wire from g10 to g15, pin 2.
  4. As before: a wire from h16 (pin 3) to h23, 330 Ω from g23 to g26, the LED’s long leg in i26 and short leg in i27, and j27 to −.
What you should see

The LED lights only while you hold both buttons. Press either one alone and nothing happens. Write down the four rows of the truth table as you test them: 0 0 → 0, 0 1 → 0, 1 0 → 0, 1 1 → 1.

You now know what each gate does. The next part opens the chip and shows how it does it: with transistors used as switches, in pairs, in a pattern that makes NAND the simplest gate of all.

Sources for this part

Logic gates

History

Series Logic on a Breadboard
Menu

Gears & Signals · Static site · No trackers