A switch as a binary decision
A switch in a simple lamp circuit can only be in one of two states. Closed (ON) lets current through; open (OFF) stops it. Boolean logic gives these states numbers:
- switch closed = 1, switch open = 0 (this is the input);
- lamp lit = 1, lamp dark = 0 (this is the output).
With one switch, a cell and a lamp, the output simply copies the input: open switch, no current, lamp off (0); closed switch, current flows, lamp on (1).
Bits, bytes and Boolean algebra
The English mathematician George Boole worked out an algebra in which every quantity is either 0 or 1. Today it is called Boolean algebra, and it is the foundation of digital electronics and computing.
- A single 0 or 1 is a bit (binary digit), the smallest piece of data a computer can store.
- Eight bits make one byte, for example 01001101.
Boolean algebra is what an analogue-to-digital converter relies on when it writes measured values as binary numbers, and it is the tool engineers use to design digital systems. It has three basic operations: AND, OR and NOT. Circuits that carry out these operations are called logic gates. Their inputs and outputs are always either high (1) or low (0).
AND: switches in series
Put two switches, A and B, in series with a battery and a lamp. There is only one path for the current, and both switches lie on it. The lamp lights only when A and B are both closed. If either one is open, the path is broken.
| A | B | Lamp X |
|---|---|---|
| 0 (open) | 0 (open) | 0 (off) |
| 0 (open) | 1 (closed) | 0 (off) |
| 1 (closed) | 0 (open) | 0 (off) |
| 1 (closed) | 1 (closed) | 1 (on) |
A table like this, listing every possible combination of inputs with the output for each, is called a truth table. The AND operation is written and read "X equals A AND B".
OR: switches in parallel
Now put switches A and B in parallel with each other, the pair in series with the lamp. Each switch sits on its own branch, so current can reach the lamp through either one. The lamp lights if A is closed, or B is closed, or both. It stays off only when both are open.
| A | B | Lamp X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
The OR operation is written and read "X equals A OR B". Here the plus sign is a logic symbol, not ordinary addition: in OR logic gives 1.
NOT: the inverter
NOT has a single input and simply flips it: an input of 1 gives an output of 0, and 0 gives 1. It is written ("X equals NOT A").
| A | X = NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
A switch circuit can copy this too (beyond the book). Connect a resistor and a lamp in series with the battery, then fit a switch across the lamp. With the switch open, current flows through the lamp and it lights. Closing the switch gives the current an easy path round the lamp, so the lamp goes out: input 1, output 0.
Worked example 1: counting combinations
How many rows does the truth table of a two-input operation need? How many for three inputs?
Each input can be 0 or 1, so every extra input doubles the number of combinations:
Worked example 2: three switches in series
A machine runs only when three safety switches, A, B and C, are all closed, because they are wired in series. Which of its 8 input combinations make it run?
Only one: , , . Every other row contains at least one 0, which breaks the single path. This is AND logic with three inputs, .
Worked example 3: bits and bytes
(a) How many bits are there in 4 bytes? (b) How many different patterns can one byte hold?
(a) bits.
(b) Each of the 8 bits doubles the count, so one byte can hold different patterns (00000000 up to 11111111). This part goes beyond the book.
Boolean logic in the simulation
Use the circuit builder to test both switch models yourself.
- Pick Empty under Starting circuits, then place a Lamp and two Switch parts so that everything forms one loop with the battery (join the gaps with Wire).
- Use Select, click a switch and tick or untick Switch closed. Work through all four rows of the AND truth table and check that the lamp lights only for 1, 1.
- Rebuild it with the two switches on separate branches that rejoin before reaching the lamp. Now the lamp is off only when both switches are open: OR logic.
- For NOT, place a resistor and a lamp in the loop and a switch across the lamp's two ends. Closing that switch puts the lamp out.