Although this chapter is about alternative number bases (including binary), it concludes with two circuits that demonstrate how binary numbers can be interpreted or generated by circuits using logic gates.
The first circuit, called a decoder, shows the decimal value of a three digit binary number. Toggle the switches at the top with mouse clicks or finger taps. The illuminated light at the bottom shows the value of that binary number. For example, binary 101 is decimal 5.
This second circuit is called an encoder. Use your mouse or finger to drag the oblong bar at the top to a particular decimal number from 0 through 7. The output at the bottom shows the value of that number in binary. For example, decimal 6 is binary 110.
In Chapter 8, you were introduced to the four standard two-input gates: AND, OR, NAND, and NOR. But you may have wondered: Are there others, and if so, how many others are there?
Sixteen. There are 16 unique two-input gates.
You can convince yourself of this fact by putting together a table that shows all the combinations of inputs (represented by A and B) and the resultant output. Each row starting with the row labeled Output is a different possible two-input gate:
A: | 0 | 0 | 1 | 1 |
---|---|---|---|---|
B: | 0 | 1 | 0 | 1 |
Output: | 0 | 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 | 0 | 0 | 0 | |
1 | 0 | 0 | 1 | |
1 | 0 | 1 | 0 | |
1 | 0 | 1 | 1 | |
1 | 1 | 0 | 0 | |
1 | 1 | 0 | 1 | |
1 | 1 | 1 | 0 | |
1 | 1 | 1 | 1 |
You know you've accounted for all the possibilities because the sixteen rows of Output are the binary numbers for 0 through 15.
Some of these possible two-input gates are trivial, such as the first and last, which don't depend on any of the inputs. Some of them only depend on one of the inputs. But they all can be represented by combinations of more basic logical operations possible with the standard four gates and the inverter:
A: | 0 | 0 | 1 | 1 | |
---|---|---|---|---|---|
B: | 0 | 1 | 0 | 1 | Logical operation |
Output: | 0 | 0 | 0 | 0 | 0 (ground) |
0 | 0 | 0 | 1 | AND | |
0 | 0 | 1 | 0 | A AND NOT B | |
0 | 0 | 1 | 1 | A | |
0 | 1 | 0 | 0 | NOT A AND B | |
0 | 1 | 0 | 1 | B | |
0 | 1 | 1 | 0 | (A OR B) AND (A NAND B) | |
0 | 1 | 1 | 1 | OR | |
1 | 0 | 0 | 0 | NOR | |
1 | 0 | 0 | 1 | (A NOR B) OR (A AND B) | |
1 | 0 | 1 | 0 | NOT B | |
1 | 0 | 1 | 1 | A OR NOT B | |
1 | 1 | 0 | 0 | NOT A | |
1 | 1 | 0 | 1 | NOT A OR B | |
1 | 1 | 1 | 0 | NAND | |
1 | 1 | 1 | 1 | 1 (V) |
If you study this table closely, you'll see that the top half of the Output section is a mirror image of the bottom half: 0 (the top row) is the opposite of 1 (the bottom row); AND (the second row) is the opposite of NAND (the penultimate row); and so forth.
The two longest and most complex logical operations are towards the center. In the first case, the output is 1 when either A and B is 1 but not both; and in the second case, the output is 1 when either A and B are both 0 or both 1.
The first case — an output is 1 when either A or B is 1 but not both — turns out to be very important for performing a very common task, as you'll see in Chapter 14.