Electrical Engineering › Section S · Logic gates and Boolean algebra › Topic S.1

Inverter, AND, OR, NAND, NOR, and XOR gates

Six kinds of gate, plus the XNOR, are the building blocks of all digital hardware. This topic gives each one's symbol, Boolean expression and truth table, shows how to work out gate outputs from timing waveforms, and introduces active-LOW signals and the equivalent forms of NAND and NOR.

Symbols, bubbles and active-LOW signals

Each gate has two standard symbols: the familiar distinctive shapes, and a rectangular form defined by IEEE Std 91 and IEC 60617, in which a qualifying symbol inside the box names the function: & for AND, ≥1 for OR, =1 for XOR and 1 for a buffer or inverter. A small circle, the bubble, on an input or output marks inversion; rectangular symbols may use a small triangle instead. A signal whose active, or asserted, state is LOW is called active-LOW, and its name carries an overbar, such as \(\overline{\text{EN}}\) for an enable that works when LOW. A bubble on an input shows that the input is active-LOW.

The inverter

The inverter, or NOT gate, outputs the complement of its input, \(X = \overline{A}\). On a timing diagram its output is the input waveform turned upside down: HIGH wherever the input is LOW, and the reverse, edge for edge. A row of eight inverters forms the 1's complement of a byte, as "Complements and signed numbers" described. A bubble on the output of the symbol shows an active-LOW output; drawn on the input instead, it means the same function, read as "the output is HIGH when the input is LOW".

AND and OR gates with many inputs

An AND gate's output is HIGH only when every input is HIGH: \(X = ABC\) for three inputs. An OR gate's output is HIGH when at least one input is HIGH: \(X = A + B + C\). Each extra input doubles the truth table, so a 3-input gate has 8 rows and a 4-input gate 16. Only one of those rows gives a HIGH from an AND gate, all inputs 1, and only one gives a LOW from an OR gate, all inputs 0. In fixed-function form these are 2-, 3- and 4-input parts, and wider functions are built by combining gates.

Worked example: AND as an enable gate

An AND gate can pass or block a signal. Feed a clock to input A and an enable pulse to input B: while B is HIGH the output copies the clock, and while B is LOW the output stays LOW. A frequency counter uses exactly this: a counter counts the pulses that get through during an enable pulse of known length. 1. Suppose the enable is HIGH for exactly 1.000 ms and the counter records 4750 pulses. 2. The frequency is pulses per unit time: \(f = 4750 / 1.000\,\text{ms}\). 3. So \(f = 4.75\,\text{MHz}\). Check: a 1 s enable would count 4,750,000 pulses, the same rate.

The NAND gate

NAND means NOT-AND: an AND followed by an inverter, drawn as an AND symbol with an output bubble. Its expression is \(X = \overline{AB}\), and its output is LOW only if every input is HIGH. Reading its truth table another way gives the negative-OR view: the output is HIGH when A is LOW or B is LOW. So a NAND can also be drawn as an OR shape with bubbles on both inputs and none on the output; the two symbols describe the same gate. In CMOS, NAND and NOR need fewer transistors than AND and OR, which add an inverting stage.

The NOR gate

NOR means NOT-OR, \(X = \overline{A + B}\): its output is HIGH only if every input is LOW, and any HIGH input makes it LOW. The negative-AND view reads the same table as "the output is HIGH when A is LOW and B is LOW", drawn as an AND shape with bubbles on both inputs. Choosing the symbol whose bubbles match the active levels of the signals makes a schematic easier to read. Why these pairs of symbols are equivalent is the subject of "Boolean operations, laws, and DeMorgan's theorems".

Worked example: an active-LOW door warning

Two door switches give active-LOW signals \(\overline{D_1}\) and \(\overline{D_2}\): each line goes LOW when its door is open. A warning lamp W must light (HIGH) when either door is open. Which gate? 1. The lamp must be HIGH when \(\overline{D_1}\) is LOW or \(\overline{D_2}\) is LOW: a negative-OR. 2. A negative-OR is a NAND, so \(W = \overline{\overline{D_1}\,\overline{D_2}}\). 3. Check every case:

\begin{array}{cc|c} \overline{D_1} & \overline{D_2} & W \\ \hline 0&0&1 \\ 0&1&1 \\ 1&0&1 \\ 1&1&0 \end{array}

Only with both lines HIGH, both doors shut, is the lamp off.

XOR and XNOR

The exclusive-OR (XOR) gate outputs HIGH when its two inputs differ: \(X = A \oplus B\). Unlike OR, it gives LOW when both inputs are HIGH. The exclusive-NOR (XNOR), \(X = \overline{A \oplus B}\), outputs HIGH when the inputs are equal, so it is an equality detector. XOR gates appear wherever bits are compared or added: the sum bit of a 1-bit addition is \(A \oplus B\), and a chain of XORs gives a parity bit. To test two 4-bit numbers for equality, XOR the matching bits; 1011 and 1001 give 0010, and a NOR of those four results gives 1 only if all are 0, here 0, not equal.

All six two-input functions

The full set for two inputs, with NAND, NOR and XNOR as the complements of AND, OR and XOR:

\begin{array}{cc|cccccc} A&B&AB&A{+}B&\overline{AB}&\overline{A{+}B}&A{\oplus}B&\overline{A{\oplus}B} \\ \hline 0&0&0&0&1&1&0&1 \\ 0&1&0&1&1&0&1&0 \\ 1&0&0&1&1&0&1&0 \\ 1&1&1&1&0&0&0&1 \end{array}

Read across a row to see every gate's response to one input pair, or down a column for one gate. Each complementary pair of columns is opposite in every row.

Worked example: outputs from waveforms

Over six equal intervals, input A is 0, 1, 1, 0, 1, 0 and input B is 1, 1, 0, 0, 1, 1. Find the AND, NAND and XOR outputs. 1. Work interval by interval, since gates respond to the present inputs only. 2. AND is 1 only where both are 1: intervals 2 and 5, so 0, 1, 0, 0, 1, 0. 3. NAND is its complement: 1, 0, 1, 1, 0, 1. 4. XOR is 1 where the inputs differ, intervals 1, 3 and 6: 1, 0, 1, 0, 0, 1. Check: in interval 5 both inputs are 1, so AND is 1, NAND 0 and XOR 0, consistent with the table.

Common mistakes to avoid

First, treating XOR like OR: with both inputs HIGH, OR gives 1 but XOR gives 0. Second, writing NAND as \(\overline{A}\,\overline{B}\); the bar must cover the whole product, \(\overline{AB}\), and the two are different functions. Third, reading a bubble as a delay or a buffer rather than an inversion. Fourth, forgetting that an active-LOW signal's overbar is part of its name: \(\overline{\text{EN}} = 0\) means enabled. Fifth, assuming a NAND symbol and a negative-OR symbol are different gates; they are one gate drawn two ways.

Key takeaways

Inverter: \(X = \overline{A}\). AND: \(X = AB\), HIGH only if every input is HIGH. OR: \(X = A + B\), HIGH when any input is HIGH. NAND, \(\overline{AB}\), is LOW only if every input is HIGH, equivalent to a negative-OR. NOR, \(\overline{A + B}\), is HIGH only if every input is LOW, equivalent to a negative-AND. XOR, \(A \oplus B\), is HIGH when inputs differ; XNOR when they match. A bubble means inversion, and an overbar on a signal name means active-LOW. AND gates can enable or inhibit a signal, and timing problems are solved interval by interval.

Flashcards

Flashcard

Bubble

Inversion at a gate input or output

An input bubble marks an active-LOW input.

Test your understanding

Question 1 of 5

A 2-input gate gives output 1 for inputs 01 and 10, and 0 for inputs 00 and 11. Which gate is it?

Question 2 of 5

What is the output of a 3-input NOR gate with inputs A = 0, B = 0 and C = 1?

Question 3 of 5

A frequency counter's AND gate is enabled for 10.0 ms and the counter records 3,200 pulses. What is the input frequency?

Question 4 of 5

Which statement about a NAND gate is true?

Question 5 of 5

An enable line is named EN with an overbar. What does that tell you?

← Previous topicNext topic →