sciandu
Technology & electronics

Technology & electronics

Logic in hardware

Tiny switches become AND, OR and NOT: how a chip learns to calculate from pure logic.

Your phone contains billions of tiny switches. None of them can calculate, none of them knows numbers. And yet the phone plays videos and solves maths problems faster than any human. The secret: you can build a clever out of a huge number of dumb switches. In this topic we look at how that works.

From transistor to gate

The most important building block is the . A transistor is an electrical switch with no moving parts: apply a small voltage to its control input and it lets current through, otherwise it blocks. That is all it can do. But just a few transistors together form a , a circuit that turns one or two input signals into one output signal. The signals have only two states: voltage present means 1, no voltage means 0.

AND, OR and NOT as circuits

You can picture the three basic gates with switches. AND: two switches one after the other in a single wire. Current only flows if both are closed, so the output is 1 only if both inputs are 1. OR: two switches side by side on two parallel paths. It is enough for one of them to be closed. NOT: a switch that flips the output exactly, 1 becomes 0 and 0 becomes 1. In real chips, transistors play the role of the switches, and a NOT gate needs only two of them.

Logic gate
A
B
Output
ABAND
000
010
100
111

1 AND 0 = 0

Try it: flip the inputs and watch when the output turns into a 1.

From gate to adder

Now comes the trick that turns logic into calculation. consist only of 0 and 1, and the addition rules for a single digit are tiny: 0 plus 0 is 0, 0 plus 1 is 1, and 1 plus 1 is 0 with a carry of 1 into the next digit. Exactly these rules can be rebuilt with a few gates. The circuit is called a half adder. It only adds two single digits, though, and cannot take in a carry from the digit before. That is why two half adders and an OR gate together make a full adder, which counts the incoming carry as well. Line up full adders and pass the carry from digit to digit, and you get an adder for numbers of any length. Your adds 64 digits at once this way, many billions of times per second.

Why chips can only do what logic can

Everything a chip does is, in the end, a giant nesting of AND, OR and NOT. Multiplying, showing images, playing music: each of these tasks was translated into logic circuits by engineers. That also explains the limits. A chip understands nothing and guesses nothing, it only switches voltages according to fixed rules. Its apparent cleverness lives entirely in the arrangement of the gates and in the programs that run on them.

Exercises

0 of 6 solved

Time to try it yourself. You can't break anything, every attempt counts.

What job does a transistor do inside a logic gate?

When does an AND gate output a 1?

An OR gate receives 1 and 0 at its inputs. What does the output show?

Match each building block to its correct behaviour.

AND gate
OR gate
NOT gate
Transistor

A NOT gate receives a 0 at its input. What does the output show?

Order a chip's building blocks from small to large, the way they build on each other.

  1. 1Adder for long numbers
  2. 2Processor
  3. 3Transistor
  4. 4Logic gate
  5. 5Half adder