Week 27 · 4.3–4.4 Data compression, logic gates and truth tables · 3 lessons
2
Gates that decide
Computing 8: Topics 4.3–4.4, pp. 268–282
GoalDescribe the NOT, AND and OR logic gates and complete their truth tables.
New words
logic gate · a tiny part of a circuit that takes inputs of 0 or 1 and gives one outputtruth table · a table that shows the output for every possible set of inputsinput, output · what goes into a gate, and what comes out
Explanation
Computers are built from circuits that contain many tiny logic gates. A gate takes inputs, which are 1 (on) or 0 (off), and gives one output. A NOT gate has one input and reverses it: 0 becomes 1 and 1 becomes 0. An AND gate has two inputs. Its output is 1 only when both inputs are 1. An OR gate also has two inputs. Its output is 1 when at least one input is 1. A truth table lists every possible input and its output. A NOT table has 2 rows, because one input has 2 values. AND and OR tables have 4 rows, because two inputs give 2 × 2 = 4 combinations.
Gate
Inputs
Rule
Rows in the table
NOT
1
reverses the input
2
AND
2
1 only if both are 1
4
OR
2
1 if one or both are 1
4
Worked examples
Input
Output
0
1
1
0
The NOT gate. If the input is 0 the output is 1. If the input is 1 the output is 0.
A
B
Output
0
0
0
0
1
0
1
0
0
1
1
1
The AND gate. Think of two keys that must both be turned to open a safe. Only one row has output 1: when both inputs are 1.
A
B
Output
0
0
0
0
1
1
1
0
1
1
1
1
The OR gate. Think of two doors into a garden: you can enter by either one or both. Only one row has output 0: when both inputs are 0. Python’s not, and and or work in the same way on True and False.
Class activity
Human gates (no computer). Three people stand in a row. Each of two “input” people holds up a card: 1 (hand up) or 0 (hand down). The third person is the gate and shows the output. Play AND: the gate raises a hand only when both inputs are up. Play OR, and then NOT with one input. Write each result in a truth table as you go. For AND and OR, make sure you play all four combinations. Then check each table by comparing with a partner. Explain why there must be four rows for two inputs. Play again with the gate secretly chosen by a partner, and see if you can work out which gate it is.
Practice
1
Complete the AND table. Then say what a NOT gate outputs when its input is 0.
A
B
A AND B
0
0
?
0
1
?
1
0
?
1
1
?
AND: 0 0 gives 0; 0 1 gives 0; 1 0 gives 0; 1 1 gives 1. A NOT gate reverses 0, so it outputs 1.
2
Complete the OR table. The rows are in a different order from the lesson.