Logic Gates

Here is an adder, a machine that adds numbers. Click on the green + and - buttons to operate it. The adder takes the two numbers just below the buttons, adds them together, and spews the result at the bottom.

Here’s how the adder works. It is made of electronic logic gates. Electronic logic gates use electric wires to move numbers around. When a current flows in the wire (marked in cyan), it represents the number 1, and when the current is off (black) it represents the number 0.

There are different kinds of logic gates:

This is an or-gate. The gate produces 1 if it receives 1 through the top input wire or through the bottom input wire.

This is an and-gate. It produces 1 if it receives 1 through the top input wire and through the bottom input wire.

This is a xor-gate. It produces 1 if it receives 1 through the top input wire or through the bottom input wire, but not both! If both input wires are 1 it produces 0.

Logic gates can only work on the numbers 1 and 0, but using the Binary numeral system, we can combine 0s and 1s to form larger numbers. Here is a table listing the Binary representation of the numbers 0-7.

Decimal Binary
00
11
210
311
4100
5101
6110
7111

So here’s how our adder machine works. We cannot feed it our input numbers directly, but use their binary representation, according to the table above. Those 0s and 1s start flowing in the wires into the logic gates. Each logic gate functions according to its type: either ‘and’ or ‘xor’ (you can distinguish between them according to their shape). The logic gates are cleverly connected to each other, so that the correct result flows out at the bottom!

See also


Proof that computers can't do everything

A physics riddle

NEW!
Demonstration of Compression

A book about computers for ages 9+