CODE
The Hidden Language of Computer Hardware and Software
2nd Edition

Chapter 10. Alternative 10s

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.

Three-to-Eight Decoder (page 114)

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.

Your browser does not support the canvas element.

Eight-to-Three Encoder (page 116)

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.

Your browser does not support the canvas element.

How Many Two-Input Gates Are There?

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:0011
B:0101
Output:0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

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:0011
B:0101Logical operation
Output:00000 (ground)
0001AND
0010A AND NOT B
0011A
0100NOT A AND B
0101B
0110(A OR B) AND (A NAND B)
0111OR
1000NOR
1001(A NOR B) OR (A AND B)
1010NOT B
1011A OR NOT B
1100NOT A
1101NOT A OR B
1110NAND
11111 (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.