2.4.1 Boolean logic
Computers make decisions with logic. Every decision is built from tiny parts called logic gates, and each gate works with only two values: 1 and 0. At GCSE you need three gates: AND, OR and NOT.
A truth table lists every possible combination of inputs and shows the output for each one. With one input there are 2 rows. With two inputs there are 4 rows. With three inputs there are 8 rows. Each extra input doubles the number of rows.
The NOT gate
Symbol: a triangle pointing to the right with a small circle on its tip. There is one input line on the left and one output line leaving from the circle.Rule: the output is the opposite of the input.| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
The AND gate
Symbol: a shape with a flat back and a curved front, like the capital letter D. Two input lines go into the flat back. One output line leaves from the curved front.Rule: the output is 1 only when both inputs are 1.| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The OR gate
Symbol: a shape with a curved back that dips inwards and two curved sides that meet at a point at the front, like a shield. Two input lines go into the curved back. One output line leaves from the point.Rule: the output is 1 when at least one input is 1.| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Logic diagrams
A logic diagram joins gates together. The output of one gate becomes an input to the next. In the exam you may be given a diagram and asked to write what it does, or be given a statement and asked to draw the diagram. Here a diagram is described in words and written as an expression.
Example: inputs A and B go into an AND gate. Input C goes into a NOT gate. The output of the AND gate and the output of the NOT gate go into an OR gate. The output of the OR gate is P.
You write this as an expression:
P = (A AND B) OR NOT C
Brackets show what is worked out first. NOT applies only to the single input right after it, so NOT C means "the opposite of C". Always put brackets around a pair of inputs joined by a gate, so there is no doubt what you mean.
Building a truth table for a combined expression
Do not try to work out the final answer in your head. Add a working column for each part of the expression, and then use the working columns to get the output.
P = (A AND B) OR NOT C.Step 1: three inputs, so write 8 rows. Count from 000 up to 111 in binary so that no row is missed.
Step 2: add a working column for A AND B.
Step 3: add a working column for NOT C.
Step 4: P is 1 whenever A AND B is 1 or NOT C is 1.
| A | B | C | A AND B | NOT C | P |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
Check row 7: A = 1, B = 1, C = 0. A AND B is 1. NOT C is 1. 1 OR 1 is 1, so P is 1.
Using logic to solve a problem
Logic is used to turn a real situation into an expression. Pick a letter for each input and for the output, say what 1 means for each, and join them with AND, OR and NOT.
Problem: A school door unlocks (O = 1) when a valid card is scanned (V = 1) and the building is not in lockdown (L = 1 means lockdown).* "Card scanned and not in lockdown" means V AND NOT L.
* The expression is O = V AND NOT L.
| V | L | NOT L | O |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
The door unlocks only in row 3: a valid card and no lockdown. In every other case it stays locked. The words "and", "or" and "not" in a problem usually tell you which gate to use. If a problem says "either ... or", use OR.
Other notation
Exam questions and mark schemes accept other ways of writing the same thing.
* T and F can be used instead of 1 and 0. T means true (1) and F means false (0).
* OR can be written with a "V" shape: A ∨ B.
* AND can be written with an upside down "V" shape: A ∧ B.
* NOT can be written with a small hook before the input: ¬A.
Whichever notation you use, the tables give the same results. Use one style in an answer and do not mix them.
Exam technique
* State or give: write the output of a gate for the inputs given, or name the gate.
* Describe: for a gate symbol, say what shape it is and how many inputs and outputs it has. For a gate's rule, say when the output is 1.
* Complete a truth table: write every row, add working columns, and check each row. For n inputs you need 2 to the power n rows.
* Write an expression: use AND, OR and NOT with brackets, and check that each input is used.
* Solve a problem: say what each letter means, then write the expression, then use a table to test it.