What a logic gate is
Inputs in, one output out, and a table that says everything there is to say about it.
A box with a rule
So far a wire has only ever carried a bit from one place to another. Nothing has been done to it. A logic gate is the smallest thing that does something: a little circuit with a few wires going in, one wire coming out, and a fixed rule that decides what the output is from what the inputs are. That is all a gate is. It does not remember anything, it does not wait for anything, and it has no settings. Put values on its inputs and, a moment later, the rule has put a value on its output.
Here is one gate to try. Its rule is "output 1 only when both inputs are 1". Click the inputs and watch the output wire change colour.
Why the rule is the whole story
Because every input can only be 0 or 1, a gate can only ever be asked a small number of questions. A gate with two inputs can see four situations: both off, only the second on, only the first on, both on. That is the same counting you did with bits in the last stage: two bits, four patterns. A three-input gate sees eight situations, a four-input gate sixteen. In general, n inputs give 2n situations, and each one has an answer.
So if you write down the answer for every situation, you have described the gate completely. There is nothing left to say about it. Two gates built in completely different ways, one from transistors and one from relays or from two switches on a battery, are the same gate if their lists of answers match. Engineers call that list a truth table, and it is the one tool you will use in every lesson from here on.
Reading a truth table
Look at the table under the gate above. The two left columns are the inputs a and b. Read the rows top to bottom and you will see the inputs counting up in binary: 00, 01, 10, 11. That is the convention everywhere, and it is why counting in binary came before this lesson. Row one is always all zeros, the last row is always all ones, and every pattern appears exactly once in between. The right column, out, is the answer for that row.
To read the table for a particular case, find the row whose inputs match and read across. To write one for a gate you are describing, put the input columns down first, counting up from all zeros, and only then think about the output column one row at a time. Writing the inputs in counting order is what stops you from missing a row or listing one twice.
Worked example. The gate above has the rule "1 only when both inputs are 1". Fill in its truth table.
Two inputs, so 22 = 4 rows. Write the inputs counting up: 00, 01, 10, 11. Now the rule, row by row. 00: both are 0, not both 1, so 0. 01: only b is 1, so 0. 10: only a is 1, so 0. 11: both are 1, so 1. The output column reads 0, 0, 0, 1, which is what the widget shows.
Here is a gate with three inputs and the same rule, so you can see a table with eight rows. Click through them.
Why?: why does the order of the rows matter?
It does not change what the gate does, but it matters to people. If every table on the site, in every textbook and in every datasheet counts up from 0, then you can compare two tables by looking at their output columns alone, and you can find a row without searching. The output column on its own, read top to bottom, becomes a kind of fingerprint for the gate: 0001 is the gate above and nothing else.
Common mistake: reading the row number as the answer
It is easy to look up "a = 1, b = 0" and come back with "row 3", or with the input pattern 10 itself, rather than with the value in the output column. The row is where you look; the output column is what you read. Put your finger on the input columns, slide it right, and only then read.
What comes next
There are seven gates with names, and this stage takes them a couple at a time. Every one of them is just a different output column over the same input columns. Once you can read a truth table, no gate can surprise you: if you are ever unsure what a gate does, its table settles it.
What to remember
- A logic gate has inputs and one output, and a fixed rule that decides the output from the inputs right now.
- A gate with n inputs can see 2n different input combinations.
- A truth table lists every combination with the gate's output for it, and describes the gate completely.
- The input columns count up in binary from all zeros, so every combination appears exactly once.
- Two gates with the same truth table are the same gate, however they are built.
Build it: the introduction circuit in the simulator.
Check yourself
Get 5 right in a row and the lesson is done. A wrong answer costs the run, not the lesson.
This truth table describes a gate. What does the gate output when a = 0, b = 0, c = 0?
| a | b | c | out |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Already know this? and come back to the quiz any time.