Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [45]
Similarly, if the second switch is closed, we want a tan cat:
And if both switches are closed, we want a cat of an "other" color:
Now let's combine all four little circuits into one big circuit. (As usual, the black dots indicate connections between wires in the circuit; wires that cross without black dots are not connected.)
Yes, I know this set of connections now looks very complicated. But if you trace through very carefully—if you look at the two inputs to each AND gate to see where they're coming from and try to ignore where they're also going—you'll see that the circuit works. If both switches are off, the W output will be 1 and the rest will be 0. If the first switch is closed, the B output will be 1 and the rest will be 0, and so forth.
Some simple rules govern how you can connect gates and inverters: The output of one gate (or inverter) can be the input to one or more other gates (or inverters). But the outputs of two or more gates (or inverters) are never connected to one another.
This circuit of four AND gates and two inverters is called a 2-Line-to-4-Line Decoder. The input is two bits that in various combinations can represent four different values. The output is four signals, only one of which is 1 at any time, depending on the two input values. On similar principles, you can make a 3-Line-to-8-Line Decoder or a 4-Line-to-16-Line Decoder, and so forth.
The simplified version of the cat-selection expression was
(N x ((M x (W + T)) + (F x (1 – W)))) + B
For every + sign in this expression, there must be an OR gate in the circuit. For every x sign, there must be an AND gate.
The symbols down the left side of the circuit diagram are in the same order as they appear in the expression. These signals come from the switches wired with inverters and the 2-line-to-4-line decoder. Notice the use of the inverter for the (1 – W) part of the expression.
Now you might say, "That's a heck of a lot of relays," and yes, that's true. There are two relays in every AND gate and OR gate, and one relay for each inverter. I'd say the only realistic response is, "Get used to it." We'll be using a lot more relays in the chapters ahead. Just be thankful you don't actually have to buy them and wire them at home.
We'll look at two more logic gates in this chapter. Both use the output of the relay that normally has a voltage present when the relay is untriggered. (This is the output used in the inverter.) For example, in this configuration the output from one relay supplies power to a second relay. With both inputs off, the lightbulb is on:
If the top switch is closed, the bulb goes off:
The light goes off because power is no longer being supplied to the second relay. Similarly, if the bottom switch is closed, the light is also off:
And if both switches are closed, the lightbulb is off:
This behavior is precisely the opposite of what happens with the OR gate. It's called NOT OR or, more concisely, NOR. This is the symbol for the NOR gate:
It's the same as the symbol for the OR except with a little circle at the output. The circle means invert. The NOR is the same as
The output of the NOR gate is shown in the following table:
NOR
0
1
0
1
0
1
0
0
This table shows results opposite those of the OR gate, which are 1 if either of the two inputs is 1 and 0 only if both inputs are 0.
And yet another way to wire two relays is shown here:
In this case, the two outputs are connected, which is similar to the OR configuration but using the other contacts. The lightbulb is on when both switches are open.
The lightbulb remains on when the top switch is closed:
Similarly, the lightbulb remains on when the bottom switch is closed:
Only when both switches are closed does the lightbulb go off:
This behavior is exactly opposite that of the AND gate. This is called NOT AND or, more concisely, NAND. The NAND gate is drawn just like the AND gate but with a circle at the output, meaning the output is the inverse of the AND gate:
The NAND gate has the following behavior: