Skip to main content
Logo image

Section 1.3 Operating on bits with truth tables

The simplest digital processor simply takes in one or more input bits and maps them to an output bit. For example, take a two-bit number \(x = (x_1, x_0)\) and assert the output, \(y\text{,}\) if \(x \lt 2\text{.}\) Using mathematical notation, we can express the input-output relationship as a function, \(y=f(x)\text{,}\) and write down what the function does in a table (Figure 1.3.1). Such a tabular representation of the mapping from input bits to output bits is called a truth table.
\(x\) (decimal) \(x_1\) \(x_0\) \(y\)
0 0 0 1
1 0 1 1
2 1 0 0
3 1 1 0
Figure 1.3.1. Representing the comparison operation \(x \lt 2\) as a truth table.
Truth tables can have any number of inputs and outputs. Here is one with a two-bit input \(n = (n_1, n_0)\) and a four-bit output \(y = (y_3, y_2, y_1, y_0)\text{,}\) Figure 1.3.2.
\(n\) (decimal) \(n_1\) \(n_0\) \(y_3\) \(y_2\) \(y_1\) \(y_0\)
0 0 0 0 0 0 1
1 0 1 0 0 1 0
2 1 0 0 1 0 0
3 1 1 1 0 0 0
Figure 1.3.2. A truth table with two input bits and four output bits.
The function represented by this table, \(y = f(n)\text{,}\) asserts the \(n^{th}\) output bit, \(y_n\text{.}\) It is called a one-hot decoder (because only one output is asserted, or “hot”, at a time).

Checkpoint 1.3.3.

Write a truth table for a function \(y = f(x)\) that asserts a single output bit if the two-bit input is an odd number (zero is neither even nor odd).
Answer.
\(x\) (decimal) \(x_1\) \(x_0\) \(y\)
0 0 0 0
1 0 1 1
2 1 0 0
3 1 1 1

Checkpoint 1.3.4.

Write a truth table for a function \(g = f(x,y)\) that has two two-bit inputs. The output bit \(g\) is asserted if \(x > y\text{.}\)
Answer.
\(x_1\) \(x_0\) \(y_1\) \(y_0\) \(g\)
\(0\) \(0\) \(0\) \(0\) \(0\)
\(0\) \(0\) \(0\) \(1\) \(0\)
\(0\) \(0\) \(1\) \(0\) \(0\)
\(0\) \(0\) \(1\) \(1\) \(0\)
\(0\) \(1\) \(0\) \(0\) \(1\)
\(0\) \(1\) \(0\) \(1\) \(0\)
\(0\) \(1\) \(1\) \(0\) \(0\)
\(0\) \(1\) \(1\) \(1\) \(0\)
\(1\) \(0\) \(0\) \(0\) \(1\)
\(1\) \(0\) \(0\) \(1\) \(1\)
\(1\) \(0\) \(1\) \(0\) \(0\)
\(1\) \(0\) \(1\) \(1\) \(0\)
\(1\) \(1\) \(0\) \(0\) \(1\)
\(1\) \(1\) \(0\) \(1\) \(1\)
\(1\) \(1\) \(1\) \(0\) \(1\)
\(1\) \(1\) \(1\) \(1\) \(0\)
With this brief introduction, watch the beginning (up to time 2:21) of the following video on truth tables.
Video cover image
The small digital system called a multiplexer has two one-bit data inputs, \((A, B)\text{,}\) a control bit \(S\) (“select”), and a one-bit output, \(y\text{.}\) The control bit \(S\) selects whether the output is \(y=A\) or \(y=B\text{.}\) The function of the multiplexer is described by the following if-then-else:
if S=='0' 
    then y=A;
    else y=B;
end if;
The truth table for a two-input multiplexer has one row for each combination of the three inputs. It is good practice to organize the inputs like this:
  • From left to right, the control inputs before the data inputs
  • From top to bottom, as increasing binary numbers
Note how these two principles are applied in the truth table for the multiplexer, Figure 1.3.5.
\(S\) \(A\) \(B\) \(y\)
\(0\) \(0\) \(0\) \(0\)
\(0\) \(0\) \(1\) \(0\)
\(0\) \(1\) \(0\) \(1\)
\(0\) \(1\) \(1\) \(1\)
\(1\) \(0\) \(0\) \(0\)
\(1\) \(0\) \(1\) \(1\)
\(1\) \(1\) \(0\) \(0\)
\(1\) \(1\) \(1\) \(1\)
Figure 1.3.5. Truth table for a two-input multiplexer.
In general, a truth table with \(N\) inputs has \(2^N\) rows. Exhaustively tabulating every row can rapidly become unwieldy (4, 8, 16, 32, 64, ...) as the number of inputs increases (2, 3, 4, 5, 6, ...). Here is one way that truth tables can occasionally be compressed. Look again at the third and fourth rows of the multiplexer truth table:
\(S\) \(A\) \(B\) \(y\)
\(\vdots\) \(\vdots\)
\(0\) \(1\) \(0\) \(1\)
\(0\) \(1\) \(1\) \(1\)
\(\vdots\) \(\vdots\)
The output will be TRUE if \(S\) is FALSE and \(A\) is TRUE, whether \(B\) is TRUE or FALSE. We don’t care what the value of \(B\) is, we only need to look at \(S\) and \(A\text{.}\) We can merge the two rows into one, like this, marking \(B\)’s "don’t care" status with a dash (—):
\(S\) \(A\) \(B\) \(y\)
\(\vdots\) \(\vdots\)
\(0\) \(1\) — \(1\)
\(\vdots\) \(\vdots\)
This move reduces the number of rows from eight to seven. Additional rows can be merged using “don’t care” entries, compressing the truth table to four rows.

Checkpoint 1.3.6.

Complete the simplification of the truth table for the two-input multiplexer.
Answer.
In addition to the third and fourth rows, the first and second, fifth and seventh, and sixth and eighth can be merged:
\(S\) \(A\) \(B\) \(y\)
\(0\) \(0\) — \(0\)
\(0\) \(1\) — \(1\)
\(1\) — \(0\) \(0\)
\(1\) — \(1\) \(1\)
The if-then-else behavior of the multiplexer is concisely captured by this compact truth table.

Checkpoint 1.3.7.

A digital system has four one-bit inputs, \((x_0, x_1, x_2, x_3)\text{,}\) a two-bit binary data output \(n=(n_1, n_0)\text{,}\) and a one-bit control output \(v\text{.}\)
  • If all the inputs are 0, then \(v=0\) and \(n=00\text{.}\)
  • If one or more of the inputs is 1, then \(v=1\) and \(n\) is the largest index of the asserted inputs.
For example, if \(x_2\) and \(x_3\) are asserted, then \(v=1\) and \(n=11 \ (3)\text{.}\) Write a compact truth table for this function.
Answer.
\(x_3\) \(x_2\) \(x_1\) \(x_0\) \(v\) \(n_1\) \(n_0\)
\(0\) \(0\) \(0\) \(0\) \(0\) \(0\) \(0\)
\(0\) \(0\) \(0\) \(1\) \(1\) \(0\) \(0\)
\(0\) \(0\) \(1\) — \(1\) \(0\) \(1\)
\(0\) \(1\) — — \(1\) \(1\) \(0\)
\(1\) — — — \(1\) \(1\) \(1\)
This function is called a priority encoder. The compact truth table reveals a nested if-then-else structure:
        if x3==1 then 
            n=3; v=1;
        elsif x2==1 then 
            n=2; v=1;
        elsif x1==1 then 
            n=1; v=1;
        elsif x0==1 then 
            n=0; v=1;
        else
            n=0; v=0;
        end if;