Logic gates and truth tables
AND, OR and NOT gates
A logic gate takes binary inputs, 0 or 1, and produces an output. J277 covers AND, OR and NOT. In a circuit, AND is drawn with a flat input side and curved output side; OR has a curved input side and pointed output; NOT is a triangle with a small circle. The circle means the output is inverted.
| A | B | A AND B | A OR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
AND is 1 only when both inputs are 1. OR is 1 when at least one is 1.
Key terms
The NOT truth table
A NOT gate has one input and flips it: 0 becomes 1, and 1 becomes 0. A small circle on a gate symbol shows inversion. For example, NOT A is true when A is 0.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
The specification requires AND, OR and NOT; other gate types are not needed here.
Key terms
Boolean logic in programs
The same three operators appear in program conditions. ERL writes them as AND, OR and NOT; Python writes them in lower case:
age = 14
banned = false
if age >= 12 AND NOT banned then
print("Allowed in")
endif
The condition is true only when age >= 12 is true and banned is false, just as the output of an AND gate fed by a NOT gate is 1 only for the right inputs. Here both print Allowed in.
Completing a truth table
A truth table lists every possible combination of inputs once, with the output for each.
- With two inputs there are 4 rows: 00, 01, 10, 11.
- With three inputs there are 8 rows.
Write the inputs counting up in binary, so none is missed or repeated. If an expression has several parts, such as NOT (A AND B), add a column for each part, work them out from left to right, and use the last column as the output.
Common mistake
Missing a row is the commonest error. Check that you have 2 rows for each input: 2 × 2 = 4 for two inputs, 2 × 2 × 2 = 8 for three.