A truth table lists every possible combination of inputs and the output of the expression or circuit for each one. With n inputs there are 2n rows, so the first job is always to count the rows you owe.
This lesson builds on evaluating an expression with parentheses, because each row of a truth table is one evaluation. It is part of the Boolean logic module.
How do you build the table?
- Count the inputs and calculate the rows: 2 inputs = 4, 3 inputs = 8, 4 inputs = 16.
- Write the input rows in binary counting order, starting at all 0s and ending at all 1s.
- Add a working column for each bracket, NOT or gate output.
- Fill one column at a time, top to bottom, not one row at a time. This keeps the method steady.
- Check the row count at the end.
A quick pattern for the input columns: the right-most input alternates 0, 1, 0, 1. The next one alternates in pairs, 0, 0, 1, 1. The left-most of three inputs goes in fours, 0, 0, 0, 0, 1, 1, 1, 1.
Worked example
Complete the truth table for Q = (A AND B) OR NOT C.
Three inputs, so 23 = 8 rows.
| A | B | C | A AND B | NOT C | Q |
|---|---|---|---|---|---|
| 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 one row in full: for A = 1, B = 1, C = 1 the working is (1 AND 1) OR NOT 1 = 1 OR 0 = 1. The output column reads 1, 0, 1, 0, 1, 0, 1, 1. It has five 1s and three 0s.
The mistake to watch for
A common slip is to write only the rows that look interesting, or to repeat a row by accident.
Mistaken table for two inputs: rows 00, 01, 11, with the row 10 missing.
The output column then has three entries instead of four, and the table is incomplete.
The correction is to count the rows first and write all the input columns before touching the output. For 2 inputs, always write 00, 01, 10, 11.
Check yourself
1. Complete the truth table for Q = (A OR B) AND NOT (A AND B).
Show answer
| A | B | A OR B | A AND B | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |
The output is 1 only when the inputs are different.
2. How many rows are needed for four inputs?
Show answer
24 = 16 rows.
3. Give the output column for Q = A AND NOT B, in the order 00, 01, 10, 11.
Show answer
00: 0 AND 1 = 0. 01: 0 AND 0 = 0. 10: 1 AND 1 = 1. 11: 1 AND 0 = 0. Output: 0, 0, 1, 0.
Where this leads next
Next, read a diagram instead of a formula in interpreting a simple logic circuit. The Boolean and number-representation lab can generate small tables for you to compare with your own.
If you build the table correctly in practice but lose rows under time pressure, our teachers can work through your routine in online one-to-one Computer Science tuition.