Course 10.2Lesson 3 of 3
A truth table must have every row, in the right order, with the right outputs. This lesson gives a method that never misses a row, uses working columns for each gate, and shows how to name a gate from its output column alone.
Try the code and the simulations beside the lesson.
A truth table lists every combination of the inputs. Follow these steps every time.
A quick check on the inputs: in the column of the first input, the top half is all 0 and the bottom half is all 1. In the last input, the values take turns: 0, 1, 0, 1.
Let us complete the table for X = (A NAND B) AND (A OR B). Call the NAND output P and the OR output Q. To fit a phone screen, both working values sit in one column.
| A B | P Q | X = P AND Q |
|---|---|---|
| 0 0 | 1 0 | 0 |
| 0 1 | 1 1 | 1 |
| 1 0 | 1 1 | 1 |
| 1 1 | 0 1 | 0 |
The output column is 0, 1, 1, 0. That is the XOR column! The circuit uses three gates to do the job of one XOR gate.
Sometimes a question gives the output column and asks which gate it is. Learn the five two-input columns, with the rows in the order 0 0, 0 1, 1 0, 1 1:
Count the 1s first. AND and NOR have one 1 each. OR and NAND have three. XOR has two. Then look at where they are. AND has its 1 at the bottom, in the row 1 1. NOR has its 1 at the top, in the row 0 0.
The program stores the five two-input gates in a dictionary. It prints each output column, then finds the gate that gives a mystery column.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.