### Computational Thinking, Algorithms & Programming

Boolean Logic
Computational Thinking
Algorithm Design
Sequence, Selection & Iteration
Data Structures
Sub Programs
Producing Robust Programs
Programming Languages & IDEs
Searching & Sorting Algorithms

# Truth Tables

We have looked at how logic circuits can be drawn as diagrams with inputs and outputs. Another way of representing these is to draw a circuit as a truth table.

A truth table is a simple grid that shows each input and every possible output. We can use these to understand what our circuit is doing. This is especially useful when we start combining logic gates.

We can also express our logic gates using Boolean algebra, where we write down the logic of our gate as a Boolean expression.

In this lesson, we’ll learn about:

1. What truth tables are
2. The truth table for a NOT gate
3. The truth table for an AND gate
4. The truth table for an OR gate
Media Attachments:

## 1. What Truth Tables Are

Truth tables are used to show the outputs of a logic gate and of logic circuits (where we combine more than one logic gate together).

We create them by drawing out a table with columns for each of the inputs and outputs in our logic circuit. The table also needs to have enough rows to represent every single possible combination of inputs.

For example, if you have two inputs (which are always binary numbers), then we can have the following combinations:

• 0 0
• 0 1
• 1 0
• 1 1

So we would need four rows in our truth table.

Truth tables become extremely important as we start designing larger circuits to help us be able to identify exactly what outputs are produced from these combinations of gates.

### Further Thought

We often express Boolean logic circuits using Boolean algebra. Research what this is.

## 2. The Truth Table for a NOT Gate

We have seen how a NOT gate is represented as a logic diagram. This looks like figure 1 below.

There is only ONE possible input – which can either be a 1 or a 0.

The way we draw this as a truth table is as follows:

That’s all there is to it. If you input a 1, the output is a 0. If you input a 0, the output is a 1.

The truth table has ONE input that can have TWO POSSIBLE COMBINATIONS, so there are TWO rows in the truth table.

If we wanted to write this as a Boolean expression, we can write this as Q = NOT X.

### Further Thought

What would happen if you combined a NOT gate with an AND or OR gate?

## 3. The Truth Table for an AND Gate

We have seen that an AND circuit is two switches one after the other.

Only if BOTH switches are shut will the light go on.

If the light is ON that means we have an output of 1.

We drew this as an AND gate in a logic diagram as shown in figure 3.

For this truth table, we can see that we have two inputs, with two possible combinations, so we have FOUR rows in the truth table.

The way to build a truth table you need to write down all of the number of combinations of inputs that we can have. As we have two inputs of binary numbers, each of these can be a 1 or 0. So all of the combinations are as follows:

Once we’ve set up our truth table with our inputs, we can then write out our outputs. Remember, with an AND gate, we only get an output of 1 if BOTH inputs are 1. Otherwise, the output is 0.

If we wanted to write this as a Boolean expression, we can write this as Q = X AND Y.

### Further Thought

How many rows would you have if you had 3 inputs?

## 4. The Truth Table for an OR Gate

We have seen that an OR circuit is two switches in parallel.

If ONE of the switches are closed, the light will go on.

We drew this as an OR gate in a logic diagram as shown in figure 5.

For this truth table we again need to write down all of the number of combinations of inputs that we can have. As it has two inputs it has the same combinations as we had for the AND gate.

Once we’ve set up our truth table with our inputs, we can then write out our outputs. Remember, with an OR gate, we get an output of 1 if ONE OR BOTH inputs are 1. Otherwise, the output is 0.

If we wanted to write this as a Boolean expression, we can write this as Q = X OR Y.

### Further Thought

There is such a thing as an Exclusive OR gate. How does this differ to a standard OR gate?

## Lesson Summary

So to summarise what we’ve learnt in this lesson:

• Truth tables are ways of summarising the output of any input to a logic circuit.
• When completing a truth table, we should first identify all possible combinations of inputs.
• The output of a NOT truth table is the opposite of the input.
• The output of an AND truth table is 1 when both inputs are 1, otherwise it is 0.
• The output of an OR truth table is 0 when both inputs are 0, otherwise it is 1.
Quizzes