How do 0s and 1s make decisions?
A computer does not think its way to a decision. The decision is in how its switches are wired.
At a glance
A computer does not make decisions by thinking. Its decisions come from how its on (1) and off (0) switches are wired together. Wire two switches in a row, and the light comes on only when both are on. That is AND, like a microwave that runs only when the door is closed and the start button is pressed. Wire them side by side, and the light comes on when at least one is on. That is OR, like a car’s dome light that turns on when either door opens. Small groups of switches like these are called logic gates. The output of one gate can switch the next one, and chaining gates together is enough to do arithmetic.
Two switches in a row: AND
Picture a microwave with two switches wired one after the other: one closes when the door shuts, the other when you press start. Current has to pass through both to reach the oven. Press start with the door open and nothing happens; close the door without pressing start and nothing happens. Only when both are on does it run. In logic, this is called AND: the output is on only when every input is on.
Two switches side by side: OR
Now picture a car’s dome light with two door switches wired side by side, each giving the current its own path. Open the left door and the light turns on. Open the right door and it turns on. Open both and it stays on. This is called OR: the output is on when at least one input is on.
A table like the ones in the picture, which lists every combination of inputs and the output for each, is called a truth table. Two inputs can be combined in four ways, so the entire behavior of a two-input gate fits in four rows.
Everyday “or”: OR and XOR
OR turns on when at least one input is on, including when both are. Everyday “or” often means something stricter: “soup or salad” usually means one or the other, not both. Computers have a separate gate for that, XOR (exclusive OR), which turns on only when the two inputs differ.
| A | B | OR | XOR |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 0 |
Of the four cases, OR is on in three and XOR in two.
The third basic gate: NOT
NOT takes a single input and flips it: on becomes off, off becomes on. A rule like “sound an alert if the door is not closed” (an example) can be built by passing the door-closed switch through NOT. Together, AND, OR, and NOT can express decisions with many conditions, and they can also be used to build circuits that add numbers.
Chaining gates turns logic into arithmetic
The switches inside a chip are turned on and off by electricity, so one gate’s output can feed straight into the next gate’s input. Any calculation whose result is fixed for each combination of inputs can be written as a truth table. MIT’s computer architecture course (6.004) explains that any truth table can be converted into a formula that combines AND and OR (a “sum of products”), and that the formula can then be built as a circuit of NOT, AND, and OR gates. The full adder, the basic building block of addition circuits, has a truth table too, so it can be built the same way.
Real microwaves go further
The microwave above is simplified to two switches. Real microwave ovens have safety interlocks that stop the oven from producing microwaves when the door opens. US federal rules require at least two working interlocks, and at least one of them must not be operable by any part of the body or by an object with a straight insertable length of 10 centimeters. The US Food and Drug Administration adds that a monitoring system stops the oven if one or both interlocks fail. So a real microwave is closer to a longer AND, with more conditions in a row. These are US rules; other countries set their own.
Nobody presses the switches in a chip
The diagram shows hand-operated switches, but the switches in a chip are transistors (MOSFETs). The MIT course describes a transistor as a solid-state switch with no moving parts, controlled by electric fields. And on and off do not mean “electricity” and “no electricity”; they mean a high voltage range and a low one (see Why do computers use only 0 and 1?).
ASML, which makes chipmaking equipment, explains that a chip the size of a fingernail holds billions of transistors, and that the smaller the features in a chip’s patterns, the more transistors fit and the more the chip can do.
Remember
- AND: on only when both inputs are on.
- OR: on when at least one input is on, including both.
- Gates can feed into one another, and chains of gates can do arithmetic.
Next question
The circuits here look only at which switches are on right now. Open the door and the microwave stops; close it and it has to start over. So how does a computer hold on to a result it just calculated? That question leads to the memory and storage layer.
Sources
- MIT OCW 6.004 Computation Structures (Spring 2017), L04 Combinational Logic: “We can always convert a truth table into a particular form of Boolean equation called a sum-of-products.” · “We know we can come up with a sum-of-products expression for any truth table and hence build a circuit implementation using INVERTERs, AND gates, and OR gates.” · “This particular 2-output device is a full adder, which is used as a building block in addition circuits.”
- MIT OCW 6.004 (Spring 2017), L03 CMOS Technology, MOSFET: Physical View: “It’s a solid-state switch — there are no moving parts and the switch operation is controlled by electrical fields”
- eCFR, 21 CFR 1030.10(c)(2): “Microwave ovens shall have a minimum of two operative safety interlocks.” · “At least one operative safety interlock on a fully assembled microwave oven shall not be operable by any part of the human body, or any object with a straight insertable length of 10 centimeters.”
- US FDA, Microwave Ovens: requires “two independent interlock systems that stop the production of microwaves the moment the latch is released or the door is opened” · “In addition, a monitoring system stops oven operation in case one or both of the interlock systems fail.”
- ASML, Microchip basics: “On the chip, transistors act as miniature electrical switches that can turn a current on or off.” · “A microchip the size of your fingernail contains billions of transistors” · “The smaller the features in the patterns that our systems can create, the more transistors manufacturers can fit on a chip, and the more the chip can do.”