Edexcel International Advanced Level Computer Science, point 5.3.2
Definition and function
A truth table lists every possible combination of input values for a Boolean expression and shows the output for each.
Function: it shows exactly what an expression or circuit does, checks that it matches the requirements, and proves that two expressions are equivalent.
Building a truth table
- Count the inputs, . There are rows: 2 inputs give 4 rows, 3 give 8, 4 give 16.
- List the input combinations in binary counting order (so none is missed or repeated). The rightmost input alternates fastest.
- Add a column for each part of the expression (intermediate columns), working in the order of precedence: brackets, NOT, AND, OR (5.3.1).
- Fill in the final column for the whole expression.
Using intermediate columns avoids mistakes.
Example 1:
Three inputs, so 8 rows.
| A | B | C | |||
|---|---|---|---|---|---|
| 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 |
is true when C is 0 (any A and B), or when A and B are both 1.
Example 2: (XOR) written with AND, OR and NOT
XOR can be written as .
| A | B | |||||
|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 |
The final column matches the XOR truth table, which shows the two forms are equivalent.
Using a truth table to prove equivalence (De Morgan)
Show that :
| A | B | |||||
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
The two bold columns are identical, so the expressions are equivalent.
Completing a given truth table
You may be given a partly complete table and asked to fill the gaps: work out the intermediate columns and the output, row by row, using the expression given.
You may also work backwards: write the expression from a table by taking each row where , writing an AND of the inputs (using NOT for 0s), and ORing the rows together.
For example, if is 1 only for , and for , , then .
Worked example
Task: a car warning light comes on if the door is open () and the engine is running (), or if the seat belt is not fastened () and the engine is running. Write the expression, and complete the truth table.
Expression: .
| D | E | S | ||||
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 1 |
The light is on only when the engine is running () and either the door is open or the belt is not fastened. This also simplifies to .
Exam tip: use the right number of rows (), in binary counting order. Add columns for each part of the expression, and work left to right through the precedence. Don't leave blanks. After completing the table, check one or two rows by hand. Use the notation shown in the paper.
Check yourself
How many rows are in a truth table for an expression with 5 inputs?
32 (2⁵).
Why add intermediate columns?
They break the expression into small steps, in the order of precedence, which reduces mistakes.
What is the output of A · B̅ (A AND NOT B) when A = 1 and B = 1?
0 (NOT B is 0, so 1 AND 0 is 0).
How can a truth table show that two expressions are equivalent?
Complete the table for both: if their output columns are identical for every row, they are equivalent.