Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [46]
NAND
0
1
0
1
1
1
1
0
Notice that the output of the NAND gate is opposite the AND gate. The output of the AND gate is 1 only if both inputs are 1; otherwise, the output is 0.
At this point, we've looked at four different ways of wiring relays that have two inputs and one output. Each configuration behaves in a slightly different way. To avoid drawing and redrawing the relays, we've called them logic gates and decided to use the same symbols to represent them that are used by electrical engineers. The output of the particular logic gate depends on the input, which is summarized here:
So now we have four logic gates and the inverter. Completing this array of tools is just a regular old relay:
This is called a buffer, and this is the symbol for it:
It's the same symbol as the inverter but without the little circle. The buffer is remarkable for not doing much. The output of the buffer is the same as the input:
But you can use a buffer when an input signal is weak. You'll recall that this was the reason relays were used with the telegraph many years ago. Or a buffer can be used to slightly delay a signal. This works because the relay requires a little time—some fraction of a second—to be triggered.
From here on in the book, you'll see very few drawings of relays. Instead, the circuits that follow will be built from buffers, inverters, the four basic logic gates, and more sophisticated circuits (like the 2-Line-to-4-Line Decoder) built from these logic gates. All these other components are made from relays, of course, but we don't actually have to look at the relays.
Earlier, when building the 2-Line-to-4-Line Decoder, we saw a little circuit that looked like this:
Two inputs are inverted and become inputs to an AND gate. Sometimes a configuration like this is drawn without the inverters:
Notice the little circles at the input to the AND gate. Those little circles mean that the signals are inverted at that point—a 0 (no voltage) becomes a 1 (voltage) and vice versa.
An AND gate with two inverted inputs does exactly the same thing as a NOR gate:
The output is 1 only if both inputs are 0.
Similarly, an OR gate with the two inputs inverted is equivalent to a NAND gate:
The output is 0 only if both inputs are 1.
These two pairs of equivalent circuits represent an electrical implementation of De Morgan's Laws. Augustus De Morgan was another Victorianera mathematician, nine years older than Boole, whose book Formal Logic was published in 1847, the very same day (the story goes) as Boole's The Mathematical Analysis of Logic. Indeed, Boole had been inspired to investigate logic by a very public feud that was being waged between De Morgan and another British mathematician involving accusations of plagiarism. (De Morgan has been exonerated by history.) Very early on, De Morgan recognized the importance of Boole's insights. He unselfishly encouraged Boole and helped him along the way, and is today sadly almost forgotten except for his famous laws.
De Morgan's Laws are most simply expressed this way:
A and B are two Boolean operands. In the first expression, they're inverted and then combined with the Boolean AND operator. This is the same as combining the two operands with the Boolean OR operator and then inverting the result (which is the NOR). In the second expression, the two operands are inverted and then combined with the Boolean OR operator. This is the same as combining the operands with the Boolean AND operator and then inverting (which is the NAND).
De Morgan's Laws are an important tool for simplifying Boolean expressions and hence, for simplifying circuits. Historically, this was what Claude Shannon's paper really meant for electrical engineers. But obsessively simplifying circuits won't be a major concern in this book. It's preferable to get things working rather than to get things working as simply as possible. And what we're going to get working next is nothing less than an adding machine.
Chapter 12. A Binary Adding Machine
Addition is the most basic of arithmetic operations,