Truth tables

Computer Science · Boolean logic. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science topics

The idea

A truth table lists every possible combination of inputs to a logic circuit and the output for each one. With 2 inputs there are 4 rows. With 3 inputs there are 8 rows. The rows are written in binary counting order, from 000 up to 111.

To complete a table from an expression or a circuit, do not jump straight to the final output. Work out the output of each gate or bracket first, as an extra working column, and then combine those results.

For a problem statement, first turn the words into an expression, or mark the rows where the stated conditions are met, taking care with what 1 and 0 mean for each input.

In simpler words

A truth table lists every input combination and the output for each. Two inputs give 4 rows. Three inputs give 8 rows. Write the rows in binary order from 000 to 111. Do not jump straight to the answer. Work out each gate first in its own column. Then combine those results to get the final output.

An everyday comparison

Filling in a truth table is like doing long division on paper. If you write each step, mistakes are easy to spot; if you do it all in your head, a NOT slips away. The comparison stops working because a truth table must list every possible input combination, 2n rows, not just one calculation.

Rules to remember

Common mistake

Students try to do a whole row in their head and lose a NOT on the way. Write the intermediate values for each row, and use XOR = 0 when both inputs are 1.

In the exam

Write the inputs in binary order with 2n rows. Add a working column for each gate or bracket, labelled, for example P = A AND B. Fill each working column, then combine them for the final output X. Apply NOT before the next gate uses the value. Check XOR gives 0 for 1, 1. Make sure every row is complete.

Worked example

In the eight-row truth table for X = (A OR NOT B) AND C, in how many rows is X = 1?

  1. X is an AND, so C must be 1 and (A OR NOT B) must be 1.
  2. A OR NOT B is 1 for A,B = 0,0 (NOT B = 1), 1,0 and 1,1. It is 0 only for A,B = 0,1.
  3. With C = 1 this gives the rows ABC = 001, 101 and 111.
  4. Every row with C = 0 gives X = 0, so there are no more.

Answer: 3 rows

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Logic circuits and logic expressionsTake a Computer Science test