We’ve previously used a turn to reverse the direction of a marble. But turns serve another key function:
The cyan cell only gets a marble if we input both the left marble and the right marble.
Because this cell needs both one input and the other, it’s called an AND gate, which is a particular type of logic gate.
logic gates
A logic gate is a device with these properties:
- It has a fixed number of inputs and outputs
- Each input and output is always either 0 or 1
- Each output is determined by applying a rule to the inputs
For example, our AND gate has 2 inputs and 1 output. The rule for the output is:
- 1 if the inputs are 1 and 1
- 0 otherwise
The standard way of describing a logic gate is with its truth table, where we show what output is associated with each combination of inputs:
0 | 1 | 0 | 0 | 0 |
---|---|---|
1 | 0 | 1 |
To find out the output for any given combination of inputs, look at the value in the corresponding cell.
For compactness, we’ll write our truth tables like this: . The filled-in cells correspond to a 1; the empty cells are 0. For example:
- means “always output 0, regardless of input”
- means “always output 1, regardless of input”
- means “copy input A, ignore input B”
- means “copy input B, ignore input A”
- means “only output 1 if both inputs were 1” (AND Gate)
This will help us recognise when we encounter the same truth table again later.
why does this matter?
Remember our read-transform-output loop? To build a computer, we need to be able to transform the binary representation of data.
A logic gate transforms individual bits of data. By combining them together in clever ways, we can make them transform any binary data into new data.
Think of it like cooking a meal. You can break down any recipe into tiny steps:
step | instruction |
---|---|
1 | Pick up an onion with your right hand |
2 | Put the onion on a chopping board |
3 | Pick up a knife with your left hand |
4 | Put the knife against the onion |
… | … |
2,046 | Put your right hand on the oven dial |
2,047 | Turn your right hand 30 degrees |
… | … |
3,067 | Put plate on table |
3,068 | Let go of plate |
Even though each step is simple, we can combine them to make any kind of dish. It’s the same with logic gates — each one may be simple, but by combining them together, we can make them transform any kind of data.
next
In the next few tutorials, we’ll look at some other logic gates, and start to combine them into more interesting devices.
continue