About

4.1 Boolean Operators, Truth Tables & Logic Gates

Theory: Boolean Operators, Truth Tables & Logic Gates

Everything a computer does (adding, comparing, remembering, choosing the next instruction) is ultimately built from circuits that combine two-valued signals: high voltage / low voltage, true / false, 11 / 00. Boolean algebra (George Boole, 1854) is the mathematics of such two-valued quantities, and logic gates are the electronic devices that compute it. This page builds the vocabulary: the operators, how to describe them completely with truth tables, the gates that implement them, and why two special gates (NAND and NOR) are enough to build everything (Null & Lobur, Ch. 3).

Boolean Variables and Truth Tables

A Boolean variable can take only the values 00 (false, low) or 11 (true, high). A Boolean operator takes one or more Boolean inputs and produces a Boolean output.

Because every input has only two possible values, we can list every input combination and the output for each. This list is a truth table, and it describes an operator (or any Boolean function) completely.

Mini-example

A function of 3 variables needs 23=82^3 = 8 rows; a function of 4 variables needs 24=162^4 = 16 rows. The rows for x,y,zx, y, z are 000,001,010,011,100,101,110,111000, 001, 010, 011, 100, 101, 110, 111, i.e. the numbers 00 to 77 in binary.

AND, OR and NOT

These are the three basic operators.

OperatorWrittenName in algebraOutput is 1 when…
ANDxyxy or x⋅yx \cdot yBoolean productboth inputs are 1
ORx+yx + yBoolean sumat least one input is 1
NOTx′x' (also x‾\overline{x} or ¬x\neg x)complementthe input is 0

The truth tables:

xxyyxyxy (AND)x+yx+y (OR)
0000
0101
1001
1111
xxx′x' (NOT)
01
10

Notation: Null & Lobur and many textbooks write the complement as an overbar x‾\overline{x}; the lecture uses the prime x′x', and so does this page. They mean exactly the same thing: x′=x‾x' = \overline{x}, and (xy)′=xy‾(xy)' = \overline{xy}. Some books also use the “elbow” ¬x\neg x.

Notice that AND really behaves like multiplication (1⋅1=11 \cdot 1 = 1, anything times 00 is 00) and OR behaves almost like addition, except that 1+1=11 + 1 = 1 (there is no “2” in Boolean algebra).

Mini-example

With x=1x = 1, y=0y = 0:  xy=1⋅0=0\ xy = 1\cdot 0 = 0,  x+y=1+0=1\ x + y = 1 + 0 = 1,  x′=0\ x' = 0,  y′=1\ y' = 1,  x+y′=1+1=1\ x + y' = 1 + 1 = 1.

Logic Gates

A gate is an electronic device that computes a Boolean operator: it takes one or more input voltages and produces an output voltage. Physically, a single gate is built from roughly one to six transistors. An integrated circuit (IC), or chip, packages a collection of gates on one piece of silicon.

The standard gate symbols (you must be able to recognise and draw them):

GateSymbol shapeOutput
AND“D” shape: flat back, round frontxyxy
ORcurved “shield/arrowhead”: concave back, pointed frontx+yx + y
NOT (inverter)triangle pointing right with a small bubble at the tipx′x'
XOROR shape with an extra curved line across its inputsx⊕yx \oplus y
NANDAND shape with a bubble on the output(xy)′(xy)'
NOROR shape with a bubble on the output(x+y)′(x+y)'

The bubble always means “complement here”. An AND gate followed by a bubble is a NAND; an OR followed by a bubble is a NOR. You will also see bubbles on inputs, meaning that input is complemented before entering the gate.

Exclusive OR (XOR)

XOR outputs 1 only when its inputs differ. Its symbol is ⊕\oplus.

xxyyx⊕yx \oplus y
000
011
101
110

Two useful ways to see XOR:

For more than two inputs, x⊕y⊕z⊕⋯x \oplus y \oplus z \oplus \cdots is 1 exactly when an odd number of inputs are 1, which makes XOR the natural parity generator (Lecture 3).

Mini-example

1⊕1⊕11 \oplus 1 \oplus 1: 1⊕1=01 \oplus 1 = 0, then 0⊕1=10 \oplus 1 = 1. Three 1s is odd, so the result is 11 ✓.

NAND and NOR

NAND = NOT-AND, NOR = NOT-OR. Each is simply the complement of the AND/OR column:

xxyy(xy)′(xy)' NAND(x+y)′(x+y)' NOR
0011
0110
1010
1100

Why Gates Are Naturally Inverting: the CMOS Idea

Modern chips are built in CMOS (Complementary Metal-Oxide-Semiconductor) technology. CMOS uses two kinds of transistor that act as voltage-controlled switches:

TransistorConducts (switch closed) when its input is…Placed between
pMOS0 (low)output and +5 V (pulls output up to 1)
nMOS1 (high)output and 0 V ground (pulls output down to 0)

Because a single transistor stage naturally inverts, NAND and NOR are the cheapest, fastest gates to build. An AND gate is in fact a NAND followed by an inverter (6 transistors).

Mini-example

CMOS NOR with A=0,B=1A = 0, B = 1: top pMOS (A=0A = 0) conducts, second pMOS (B=1B = 1) is off, so the series path to +5 V is broken. The nMOS on BB conducts and pulls YY to 0 V. Y=0=(0+1)′Y = 0 = (0 + 1)' ✓.

Universal Gates

NAND and NOR are called universal gates because:

  1. Any Boolean function can be built using only NAND gates, or only NOR gates.
  2. They are inexpensive to manufacture in large quantities (one gate type, mass production).
  3. They are typically faster and use less power than other gate configurations (see the CMOS idea above).

To prove universality it is enough to build NOT, AND and OR, because every Boolean function can be written using those three.

Using only NAND:

BuildConstructionWhy it works
NOT xxNAND with both inputs tied to xx(x⋅x)′=x′(x \cdot x)' = x'
xx AND yyNAND(x,yx, y), then a NAND-inverter((xy)′)′=xy((xy)')' = xy
xx OR yyinvert xx and yy with NAND-inverters, then NAND them(x′y′)′=x′′+y′′=x+y(x' y')' = x'' + y'' = x + y (DeMorgan)

Using only NOR:

BuildConstructionWhy it works
NOT xxNOR with both inputs tied to xx(x+x)′=x′(x + x)' = x'
xx OR yyNOR(x,yx, y), then a NOR-inverter((x+y)′)′=x+y((x+y)')' = x + y
xx AND yyinvert xx and yy with NOR-inverters, then NOR them(x′+y′)′=x′′y′′=xy(x' + y')' = x'' y'' = xy (DeMorgan)
OR from three NAND gatesxyx'y'x + y

Mini-example

NAND-OR check, x=0,y=1x = 0, y = 1: first stage gives x′=1x' = 1, y′=0y' = 0; final NAND gives (1⋅0)′=0′=1=0+1(1 \cdot 0)' = 0' = 1 = 0 + 1 ✓.

Multi-Input Gates and Complemented Outputs

Gates are not limited to two inputs. A 3-input OR outputs x+y+zx + y + z; a 3-input AND outputs xyzxyz. AND and OR are associative, so a 3-input AND is the same as two 2-input ANDs chained. Inputs can be complemented on the way in: an AND gate fed xx, y′y', zz produces xy′zxy'z.

A gate can also have more than one output: a common component provides both the result QQ and its complement Q′Q' (written Q‾\overline{Q} in the textbook). We will meet this again on flip-flops.

NAND and NOR are not associative. A “3-input NAND” means (xyz)′(xyz)', which is not the same as chaining two 2-input NANDs: ((xy)′z)′((xy)' z)' is a different function (see Worked Example 6).

Integrated Circuits: SSI Chips

SSI (Small-Scale Integration) chips hold a handful of gates (roughly up to 10). The classic example is the 7400 quad 2-input NAND chip: a 14-pin package in which two pins supply power (+5 V) and ground, and the remaining 12 pins serve 4 NAND gates × 3 pins (two inputs and one output each). A notch on one end marks pin orientation. Larger scales (MSI, LSI, VLSI) pack hundreds up to billions of gates.

Mini-example

A design needs 10 two-input NAND gates. Each 7400 holds 4, so we need ⌈10/4⌉=3\lceil 10/4 \rceil = 3 chips, leaving 12−10=212 - 10 = 2 gates unused.


Worked Examples

Exercise 1

Let A=10110010A = 10110010 and B=01101011B = 01101011. Apply each operator bit by bit (as a processor’s logic instructions do) and give: AA AND BB, AA OR BB, AA XOR BB, NOT AA, AA NAND BB, and AA NOR BB.

Show solution ↓
Solution

Line the bits up in columns and apply the truth table to each column independently.

b7b6b5b4b3b2b1b0
AA10110010
BB01101011
AND (both 1)00100010
OR (at least one 1)11111011
XOR (differ)11011001
NOT AA01001101
NAND (complement of AND)11011101
NOR (complement of OR)00000100

So A⋅B=00100010A \cdot B = 00100010, A+B=11111011A + B = 11111011, A⊕B=11011001A \oplus B = 11011001, A′=01001101A' = 01001101, (AB)′=11011101(AB)' = 11011101, (A+B)′=00000100(A+B)' = 00000100.

Checks:

  • NAND must be the bitwise complement of AND: 00100010→1101110100100010 \to 11011101 ✓.
  • NOR must be the complement of OR: 11111011→0000010011111011 \to 00000100 ✓.
  • XOR = OR minus the columns where both are 1 (columns b5 and b1): 1111101111111011 with b5, b1 cleared gives 1101100111011001 ✓.
Exercise 2

Construct the truth table of F=x⊕y⊕zF = x \oplus y \oplus z (include the intermediate column x⊕yx \oplus y). Describe in words when F=1F = 1, and explain how this relates to parity bits.

Show solution ↓
Solution

Work column by column: first x⊕yx \oplus y, then XOR that with zz.

xxyyzzx⊕yx \oplus yF=(x⊕y)⊕zF = (x \oplus y) \oplus znumber of 1s in xyzxyz
000000
001011
010111
011102
100111
101102
110002
111013

F=1F = 1 exactly in the rows with an odd number of 1s (1 or 3). This is the modulo-2 sum of the three bits.

Parity: to give a 3-bit word even parity we append the bit P=x⊕y⊕zP = x \oplus y \oplus z; then the total number of 1s (including PP) is always even. For example, for 101101: P=1⊕0⊕1=0P = 1 \oplus 0 \oplus 1 = 0, and 10101010 has two 1s ✓. For odd parity append P′P' instead.

Exercise 3

Show how to build NOT, AND and OR using only NOR gates. Verify each construction with a truth table showing every intermediate signal.

Show solution ↓
Solution

NOT: tie both inputs of one NOR to xx. Output (x+x)′=x′(x + x)' = x' (Idempotent law x+x=xx + x = x).

xx(x+x)′(x+x)'
01
10

Matches NOT ✓.

OR (2 gates): n1=(x+y)′n_1 = (x + y)', then n2=(n1+n1)′=n1′=x+yn_2 = (n_1 + n_1)' = n_1' = x + y.

xxyyn1=(x+y)′n_1 = (x+y)'n2=n1′n_2 = n_1'
0010
0101
1001
1101

n2n_2 column =0,1,1,1= 0,1,1,1 = OR ✓.

AND (3 gates): a=(x+x)′=x′a = (x+x)' = x', b=(y+y)′=y′b = (y+y)' = y', then out=(a+b)′=(x′+y′)′=x′′y′′=xyout = (a + b)' = (x' + y')' = x''y'' = xy by DeMorgan and Double Complement.

xxyya=x′a = x'b=y′b = y'out=(a+b)′out = (a+b)'
00110
01100
10010
11001

out=0,0,0,1out = 0,0,0,1 = AND ✓.

AND from three NOR gatesxyx'y'xy

Since NOR alone gives NOT, AND and OR, NOR is universal.

Exercise 4

Implement F=xy+zF = xy + z using only 2-input NAND gates. How many gates are needed? Verify for all 8 input combinations.

Show solution ↓
Solution

Idea: a sum of products becomes a NAND-NAND circuit. By Double Complement and DeMorgan:

F=xy+z=((xy+z)′)′=((xy)′⋅z′)′F = xy + z = \big((xy + z)'\big)' = \big((xy)' \cdot z'\big)'

So:

  • Gate 1: g1=NAND(x,y)=(xy)′g_1 = \text{NAND}(x, y) = (xy)'
  • Gate 2: g2=NAND(z,z)=z′g_2 = \text{NAND}(z, z) = z' (inverter)
  • Gate 3: F=NAND(g1,g2)=(g1g2)′F = \text{NAND}(g_1, g_2) = (g_1 g_2)'

3 NAND gates in total.

F = xy + z with NAND gatesxyz(xy)'G1z'G2G3F

Verification:

xxyyzzg1=(xy)′g_1 = (xy)'g2=z′g_2 = z'F=(g1g2)′F = (g_1 g_2)'xy+zxy + z
0001100
0011011
0101100
0111011
1001100
1011011
1100111
1110011

The last two columns agree in every row ✓. All 3 gates fit on one 7400 chip with one gate to spare.

Exercise 5

(a) How many rows does the truth table of a 5-input function have?

(b) How many different Boolean functions of 2 variables exist?

(c) A circuit needs 6 NAND gates and 5 NOR gates, all 2-input. Using 7400 (quad NAND) and 7402 (quad NOR) chips, how many chips are needed and how many gates are left unused?

Show solution ↓
Solution

(a) Each input doubles the count: 25=322^5 = 32 rows.

(b) A 2-variable truth table has 22=42^2 = 4 rows. A function is any choice of output column, and each of the 4 output bits can independently be 0 or 1: 24=162^4 = 16 functions. (AND, OR, XOR, NAND, NOR, XNOR, xx, yy, x′x', y′y', constant 0, constant 1 … are among them.) In general there are 22n2^{2^n} functions of nn variables.

(c) Gates of different types cannot share a chip.

  • NAND: ⌈6/4⌉=2\lceil 6/4 \rceil = 2 chips (8 gates), 8−6=28 - 6 = 2 unused.
  • NOR: ⌈5/4⌉=2\lceil 5/4 \rceil = 2 chips (8 gates), 8−5=38 - 5 = 3 unused.

Total 4 chips, 5 unused gates. (This is one practical reason to build everything from a single universal gate type: with NAND only, 11 gates would need ⌈11/4⌉=3\lceil 11/4 \rceil = 3 chips.)

Exercise 6

Show that NAND is not associative: compare the 3-input NAND (xyz)′(xyz)' with the chained circuit NAND(NAND(x,y),z)=((xy)′z)′\text{NAND}(\text{NAND}(x, y), z) = ((xy)'z)'.

Show solution ↓
Solution

Build both columns.

xxyyzz(xy)′(xy)'((xy)′z)′((xy)'z)'(xyz)′(xyz)'
000111
001101
010111
011101
100111
101101
110011
111010

The two last columns differ in rows 001001, 011011, 101101, so the chained circuit is not a 3-input NAND.

Algebraically: ((xy)′z)′=(xy)′′+z′=xy+z′((xy)'z)' = (xy)'' + z' = xy + z' (DeMorgan, Double Complement), while (xyz)′=x′+y′+z′(xyz)' = x' + y' + z'. These are different functions.

To make a 3-input NAND from 2-input gates, form xyxy first with an AND (NAND + inverter), then NAND with zz: ((xy)z)′=(xyz)′((xy)z)' = (xyz)'.

Exercise 7

In the CMOS NOR gate (two pMOS in series from +5 V to YY, two nMOS in parallel from YY to ground), list for each input combination ABA B which transistors conduct and the resulting output YY.

Show solution ↓
Solution

Rule: a pMOS conducts when its input is 0; an nMOS conducts when its input is 1. Y=1Y = 1 if there is a complete path to +5 V; Y=0Y = 0 if there is a path to ground.

AABBpMOS(AA)pMOS(BB)series path to +5 V?nMOS(AA)nMOS(BB)path to ground?YY
00ononyesoffoffno1
01onoffnooffonyes0
10offonnoonoffyes0
11offoffnoononyes0

The output column 1,0,0,01, 0, 0, 0 is the NOR truth table ✓. Note that in every row exactly one of the two networks conducts, so the output is never connected to both supplies at once (this is what “complementary” means, and why CMOS draws almost no static power).