Truth Tables & Basic Logic Operators
We will be using truth tables to understand how logic operators work. A truth table allows us to see all inputs and outputs related to a logic operator. For example, if we had to look at the AND operator, we have all the combinations of inputs represented in this truth table:
In the above table T stands for true and F for false. It shows the output for all possible inputs. In the computer environment, T and F are changed respectively to 1 and 0 as shown below. This table is called the truth table.
The basic logical operators are AND, OR and NOT.
We will use these truth tables in logic circuits further down to work out the outputs of a circuit based on the operators, or gates, used.
Boolean Expressions
The operators we saw in the previous section can be represented in expressions using a particular notation.
Operator | Notation | Example | Boolean Notation |
AND | . | X AND Y | X . Y |
OR | + | X OR Y | X + Y |
NOT | ' | NOT X | X' |
The Boolean operators can be joined together to form logical expressions, very much like arithmetic expressions e.g. 3 + 4 - 6.3 * 5.
Below, we have four Boolean expressions:
A + B
( A . B )' + C
A ( B + C' )
( A' + B ) . ( A + C' )
In all expressions A, B and C can only have values equal to 0 or 1 and the expression will give a result of either 0 or 1. Let us have a look at a worked example:
What is the value of A' + B if A = 0 and B = 1?
Expression at start | A' + B |
Equivalent to | ( NOT A ) OR B |
Replace inputs with values | ( NOT 0 ) OR 1 |
Evaluates to | 1 OR 1 |
Final result | 1 |
Precedence of Operators
When more than one logical operator is used in a statement you should evaluate parts of it in a certain order like we do in BIDMAS for arithmetic:
First evaluate expressions in brackets.
Then evaluate NOT.
Then evaluate AND.
Finally evaluate OR.
Time to see some examples. In all examples we will assume that A = 1, B = 0 and C = 1.
Expression at start | A + B' |
Equivalent to | A OR NOT B |
Replace inputs with values | 1 OR NOT 0 |
Evaluate NOT first | 1 OR 1 |
Evaluate OR to get final result | 1 |
Expression at start | ( A . B )' + C |
Expression at start | NOT ( A AND B ) OR C |
Replace inputs with values | NOT ( 1 AND 0 ) OR 1 |
Evaluate brackets first | NOT 0 OR 1 |
Evaluate NOT | 1 OR 1 |
Evaluate OR to get final result | 1 |
| |
Higher Order Operators
Apart from AND, OR and NOT, there are other higher-order operators which are useful for certain cases. These are the NAND (NOT-AND), NOR (NOT-OR) and XOR (Exclusive OR), as explained below.
Notice how the similarity between the image for the AND operator and the NAND operator, with the NAND having a small circle to show that the AND value is inverted.
Equivalent Expressions
How can we show that two expressions are equivalent? We do this by constructing the truth tables of both expressions and then checking that the output is the same.
Logic Gates & Circuits
A logic gate is an elementary building block of a digital circuit. Most logic gates have two
inputs and one output. At any given moment, every terminal is in one of the two binary conditions: low, represented as 0; high, represented as 1. Since electricity is analogue, binary is implemented using very distinct voltage levels. In most logic gates, the low state is approximately zero volts, while the high state is approximately five volts positive. We can combine a number of logic gates into a logic circuit, and evaluate the possible outputs using a truth table.
A Worked Example
Say we are presented with this logic gate.
First, we can label each gate with the operator, and create some temporary values at the exit of each gate for example P and Q. We should also label the final output, which we can name R.
We can then create a truth table to show each possible value through this circuit. We have 3 inputs, so our truth table will have 2^3 lines, so 8 lines. We end up with a truth table showing us the possible values for P, Q, and most importantly R which is our final output. Notice in the working we are also using expression notation to show how P and Q were worked out.
If we had to represent this as an expression, this is how it would go:
R = Q . B
Q = A + P
P = C'
Replacing P and Q with the original inputs, since we cannot use temporary values.
R = ( A+ P ) . B
R = ( A + C' ) . B
Comments