A logic gate is a circuit whose output depends only on the present state of its inputs, where every signal is one of two voltages. Call them 1 and 0, high and low, true and false — the algebra is the same, and it is the algebra George Boole wrote down in 1854, decades before there was anything electrical to apply it to.
The three that matter
AND, OR and NOT are enough to build every other gate, and every digital circuit that has ever existed.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Written A.B or AB. Think of two switches in series: both must close.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Written A + B. Two switches in parallel: either one will do.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
Written A with a bar over it, or A'.
The inverted pair: NAND and NOR
Put a NOT on the output of an AND and you get NAND; on an OR, you get NOR. On a symbol this is drawn as a small circle — a bubble — on the output, and that bubble always means the same thing: invert.
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| A | B | A NOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
The odd pair: XOR and XNOR
Exclusive-OR is 1 when the inputs are different. It is the gate that adds — the sum bit of a binary addition is just A XOR B — and the gate that compares.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Written with a plus inside a circle. Also readable as: is exactly one of them 1?
| A | B | A XNOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Reading the symbols
- Flat back, curved front — AND. It looks like the D of "AND".
- Curved back, pointed front — OR.
- A second curve at the back — XOR.
- A triangle — a buffer, which does nothing but drive harder. With a bubble it is a NOT.
De Morgan's theorem
Two identities that let you swap any AND for an OR, and they are how a circuit gets simplified on paper before anybody buys a chip.
NOT(A AND B) = (NOT A) OR (NOT B)
NOT(A OR B) = (NOT A) AND (NOT B)
In symbols the rule is easy to remember: break the bar and change the sign. Push a bubble through a gate and the gate changes shape. It matters practically, because it lets you rebuild a design around whichever chip you actually have in the drawer.
Real chips, and the rules for wiring them
| Part | Contains |
|---|---|
| 7400 | Four 2-input NAND gates |
| 7402 | Four 2-input NOR gates |
| 7404 | Six inverters |
| 7408 | Four 2-input AND gates |
| 7432 | Four 2-input OR gates |
| 7486 | Four 2-input XOR gates |
In every one of these 14-pin packages, pin 7 is ground and pin 14 is Vcc. Learn that pair and half the wiring is done.
- 1
Never leave an input floating
An unused input on a CMOS gate drifts into the undefined region, and the gate then oscillates and draws heavy current — chips have been destroyed this way. Tie every unused input to Vcc or ground, whichever suits the gate. On an unused gate, tie its inputs anywhere valid.
- 2
Decouple every package
100 nF between Vcc and ground, right at the chip. Gates switch fast and pull a current spike from the supply as they do, and on a breadboard the wiring inductance turns that spike into a voltage dip that other gates read as a real input.
- 3
Never connect two outputs together
If one drives high and the other low you have created a short across the supply, through both chips. This is not like tying inputs together. Use a gate, or a part explicitly built for it with an open-collector or three-state output.
- 4
Match the family before you mix
74LS is TTL and 74HC is CMOS, and their input thresholds differ. A 74HC input needs to get within about a volt of the rail to read as a 1, and a 74LS output does not always manage it. 74HCT exists precisely to bridge the two.