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:
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:
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.
We often express Boolean logic circuits using Boolean algebra. Research what this is.
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:
Input X | Output Q |
---|---|
1 | 0 |
0 | 1 |
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.
What would happen if you combined a NOT gate with an AND or OR 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:
Input X | Input Y | Output Q |
---|---|---|
1 | 1 | |
1 | 0 | |
0 | 1 | |
0 | 0 |
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.
Input X | Input Y | Output Q |
---|---|---|
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 0 |
0 | 0 | 0 |
If we wanted to write this as a Boolean expression, we can write this as Q = X AND Y.
How many rows would you have if you had 3 inputs?
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.
Input X | Input Y | Output Q |
---|---|---|
1 | 1 | |
1 | 0 | |
0 | 1 | |
0 | 0 |
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.
Input X | Input Y | Output Q |
---|---|---|
1 | 1 | 1 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
If we wanted to write this as a Boolean expression, we can write this as Q = X OR Y.
There is such a thing as an Exclusive OR gate. How does this differ to a standard OR gate?
So to summarise what we’ve learnt in this lesson: