Discrete MathematicsBoolean Algebra and Logic Circuits2 of 3
Boolean Algebra and Logic Circuits · 2

Logic Gates and Circuit Design

We know how to write rules for 0\zero{0}s and 1\one{1}s using truth tables and Boolean expressions, and now we need to turn those expressions into physical wires that make decisions.

1

Switches and Basic Logic Gates

Inside a computer, a wire with electricity flowing through it represents 1\one{1}, and a wire with no electricity represents 0\zero{0}. A logic gate is a switch setup that takes one or more input wires and controls whether electricity reaches the output wire.

Switches and Basic Logic Gates
Electricity=1,No electricity=0\text{Electricity} = \htmlClass{lc-green}{1}, \quad \text{No electricity} = \htmlClass{lc-orange}{0}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
AND\text{AND}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
A+B\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B}
OR\text{OR}
A\htmlClass{lc-blue}{A}
A′\htmlClass{lc-blue}{A'}
NOT\text{NOT}

In these three circuits, switches in a single line only let current reach the light when both A\inA{A} and B\inB{B} are closed (AB\inA{A}\inB{B}), parallel branches let current through whenever at least one branch is closed (A+B\inA{A} + \inB{B}), and a normally-closed switch breaks the path when pressed (A′\inA{A'}).

Wiring switches in a single line, on split branches, or normally closed turns simple on-off electricity into AND, OR, and NOT gates.
2

Translating Between Circuits and Expressions

A single gate makes one decision, but most circuits chain several gates together. We want to read the Boolean expression that a multi-gate circuit computes, and go backward from any Boolean expression to wire up its circuit.

Remember, our Boolean shorthand writes AND like multiplication, OR with a plus sign, and NOT with a prime tick mark:

A AND B=AB,A OR B=A+B,NOT A=A′\displaystyle \begin{aligned} \inA{A} \text{ AND } \inB{B} &= \inA{A}\inB{B}, \\ \inA{A} \text{ OR } \inB{B} &= \inA{A} + \inB{B}, \\ \text{NOT } \inA{A} &= \inA{A'} \end{aligned}
Translating Between Circuits and Expressions
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
C\htmlClass{lc-violet}{C}
Output= ?\text{Output} = \,\htmlClass{lc-pink}{?}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
(AB)′(\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B})'
C\htmlClass{lc-violet}{C}
C′\htmlClass{lc-violet}{C'}
(AB)′+C′(\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B})' + \htmlClass{lc-violet}{C'}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
B′\htmlClass{lc-pink}{B'}
A+B′\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B'}
(A+B′)′(\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B'})'
C\htmlClass{lc-violet}{C}
(A+B′)′C(\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B'})'\htmlClass{lc-violet}{C}
Text solution
Read the top branch from left to rightInputs A\inA{A} and B\inB{B} pass through the AND gate first, and the NOT gate right after it flips that entire wire, which requires parentheses:
Top wire\displaystyle \text{Top wire} =(AB)′\displaystyle = (\inA{A}\inB{B})'
Read the bottom branch and combine at the OR gateInput C\inC{C} passes through its own NOT gate before joining the top wire at the final OR gate:
Output\displaystyle \text{Output} =(AB)′+C′\displaystyle = (\inA{A}\inB{B})' + \inC{C'}
Build (A+B′)′⋅C(\inA{A} + \inB{B'})' \cdot \inC{C} from inside the parentheses outwardFirst invert wire B\inB{B} alone, combine it with A\inA{A} in an OR gate, and place a NOT gate on that output wire to flip the whole sum:
B→B′→A+B′→(A+B′)′\displaystyle \inB{B} \to \inB{B'} \to \inA{A} + \inB{B'} \to (\inA{A} + \inB{B'})'
AND the result with C\inC{C}Feed the (A+B′)′(\inA{A} + \inB{B'})' wire and wire C\inC{C} into a final AND gate:
Output\displaystyle \text{Output} =(A+B′)′C\displaystyle = (\inA{A} + \inB{B'})'\inC{C}
3

Designing a Sum of Products Circuit

Translating works when someone hands us a formula, but in an engineering problem we start with a plain-English rule and have to invent the circuit ourselves. We want to design a circuit for three judges A\inA{A}, B\inB{B}, and C\inC{C} whose output light turns on (1\one{1}) whenever a majority (at least two of the three judges) vote Yes (1\one{1}).

Remember, a minterm is an AND product of all the inputs for a single truth-table row, where any input equal to 0\zero{0} gets a prime so the product outputs 1\one{1} on that exact row alone.

Designing a Sum of Products Circuit
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
C\htmlClass{lc-violet}{C}
1=Yes\htmlClass{lc-green}{1} = \text{Yes}
0=No\htmlClass{lc-orange}{0} = \text{No}
?\htmlClass{lc-pink}{?}
PASS\text{PASS}
Output\text{Output}
Text solution
Write a minterm for each row where Output is 1\one{1}At least two inputs equal 1\one{1} in the rows (0,1,1)(\zero{0},\one{1},\one{1}), (1,0,1)(\one{1},\zero{0},\one{1}), (1,1,0)(\one{1},\one{1},\zero{0}), and (1,1,1)(\one{1},\one{1},\one{1}), so we OR those four minterms together into a two-layer AND-OR circuit:
Output=A′BC⏟011+AB′C⏟101+ABC′⏟110+ABC⏟111\displaystyle \begin{aligned} \text{Output} &= \underbrace{\inA{A'}\inB{B}\inC{C}}_{\zero{0}\one{1}\one{1}} + \underbrace{\inA{A}\inB{B'}\inC{C}}_{\one{1}\zero{0}\one{1}} \\ &\quad + \underbrace{\inA{A}\inB{B}\inC{C'}}_{\one{1}\one{1}\zero{0}} + \underbrace{\inA{A}\inB{B}\inC{C}}_{\one{1}\one{1}\one{1}} \end{aligned}
Pair each three-variable minterm with ABC\inA{A}\inB{B}\inC{C} to drop the variable that flipsWhen two minterms match in two variables and differ only in the third (0\zero{0} in one, 1\one{1} in the other), that third variable does not affect the outcome and drops out, and we can use ABC\inA{A}\inB{B}\inC{C} in all three pairs because ABC+ABC\inA{A}\inB{B}\inC{C} + \inA{A}\inB{B}\inC{C} == ABC\inA{A}\inB{B}\inC{C}:
A′BC+ABC=(A′+A)BC=BCAB′C+ABC=A(B′+B)C=ACABC′+ABC=AB(C′+C)=AB\displaystyle \begin{aligned} \flips{A'}\inB{B}\inC{C} + \flips{A}\inB{B}\inC{C} &= (\flips{A'} + \flips{A})\inB{B}\inC{C} \\ &= \inB{B}\inC{C} \\ \inA{A}\flips{B'}\inC{C} + \inA{A}\flips{B}\inC{C} &= \inA{A}(\flips{B'} + \flips{B})\inC{C} \\ &= \inA{A}\inC{C} \\ \inA{A}\inB{B}\flips{C'} + \inA{A}\inB{B}\flips{C} &= \inA{A}\inB{B}(\flips{C'} + \flips{C}) \\ &= \inA{A}\inB{B} \end{aligned}
OR the simplified pairs togetherCombining the three reduced terms replaces four 3-input AND gates and three NOT gates with three 2-input AND gates feeding one 3-input OR gate:
Output\displaystyle \text{Output} =AB+BC+AC\displaystyle = \inA{A}\inB{B} + \inB{B}\inC{C} + \inA{A}\inC{C}

Across all eight input combinations, the full Sum of Products circuit and the simplified AB+BC+AC\inA{A}\inB{B} + \inB{B}\inC{C} + \inA{A}\inC{C} circuit always produce the exact same output.

Checking every full three-judge combination and checking only pairs of yes votes always give the exact same majority answer.
4

Half Adders and Full Adders

Now that we can turn any truth table into hardware, we want to build a circuit that adds binary numbers. We start with a Half Adder, which adds two single bits A+B\inA{A} + \inB{B}, and then build a Full Adder, which adds a third input Cin\inC{C_{\text{in}}} for an incoming carry from a previous column.

When we add two single bits, there are four possible totals, where 1+1=2\one{1} + \one{1} = 2 is written as 10210_2 in binary:

0+0=002,0+1=012,1+0=012,1+1=102 (carry 1, sum 0)\displaystyle \begin{aligned} \zero{0} + \zero{0} &= 00_2, \\ \zero{0} + \one{1} &= 01_2, \\ \one{1} + \zero{0} &= 01_2, \\ \one{1} + \one{1} &= 10_2 \text{ (carry } \one{1}\text{, sum } \zero{0}\text{)} \end{aligned}
Half Adders and Full Adders
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
Carry\text{Carry}
Sum\text{Sum}
00\htmlClass{lc-orange}{0}\quad \htmlClass{lc-orange}{0}
01\htmlClass{lc-orange}{0}\quad \htmlClass{lc-green}{1}
10\htmlClass{lc-green}{1}\quad \htmlClass{lc-orange}{0}
11\htmlClass{lc-green}{1}\quad \htmlClass{lc-green}{1}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
Sum\text{Sum}
Carry\text{Carry}
Half Adder\textbf{Half Adder}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
A⊕B\htmlClass{lc-blue}{A} \oplus \htmlClass{lc-pink}{B}
Sum\text{Sum}
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
Carry\text{Carry}
Full Adder\textbf{Full Adder}
Half Adder\text{Half Adder}
Cin\htmlClass{lc-violet}{C_{\text{in}}}
A⊕B\htmlClass{lc-blue}{A} \oplus \htmlClass{lc-pink}{B}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
(A⊕B)⊕Cin(\htmlClass{lc-blue}{A} \oplus \htmlClass{lc-pink}{B}) \oplus \htmlClass{lc-violet}{C_{\text{in}}}
Sum\text{Sum}
CoutC_{\text{out}}
Half Adder\text{Half Adder}
Text solution
Build a Half Adder for two bits A+B\inA{A} + \inB{B}Designing a separate circuit for each output column gives an AND gate for the twos place (Carry\text{Carry}) and an Exclusive-OR gate for the ones place (Sum\text{Sum}), which turns on only when the two inputs differ:
Carry=AB,Sum=A′B+AB′=A⊕B⏟XOR gate\displaystyle \begin{aligned} \text{Carry} &= \inA{A}\inB{B}, \\ \text{Sum} &= \inA{A'}\inB{B} + \inA{A}\inB{B'} = \underbrace{\inA{A} \oplus \inB{B}}_{\text{XOR gate}} \end{aligned}
Find CoutC_{\text{out}} for a Full Adder (A+B+Cin\inA{A} + \inB{B} + \inC{C_{\text{in}}})Adding three bits produces a carry of 1\one{1} whenever the total is 22 (10210_2) or 33 (11211_2), which happens whenever at least two inputs are 1\one{1}, the exact Majority Voter expression:
Cout=A′BCin+AB′Cin+ABCin′+ABCin=AB+BCin+ACin\displaystyle \begin{aligned} C_{\text{out}} &= \inA{A'}\inB{B}\inC{C_{\text{in}}} + \inA{A}\inB{B'}\inC{C_{\text{in}}} \\ &\quad + \inA{A}\inB{B}\inC{C_{\text{in}}'} + \inA{A}\inB{B}\inC{C_{\text{in}}} \\ &= \inA{A}\inB{B} + \inB{B}\inC{C_{\text{in}}} + \inA{A}\inC{C_{\text{in}}} \end{aligned}
Find Sum\text{Sum} for a Full Adder by chaining two XOR gatesThe ones bit of the total is 1\one{1} when the total is 11 (01201_2) or 33 (11211_2), meaning an odd number of inputs are 1\one{1}, which we get by feeding A⊕B\inA{A} \oplus \inB{B} and Cin\inC{C_{\text{in}}} into a second XOR gate:
Sum=A′B′Cin+A′BCin′+AB′Cin′+ABCin=(A⊕B)⊕Cin\displaystyle \begin{aligned} \text{Sum} &= \inA{A'}\inB{B'}\inC{C_{\text{in}}} + \inA{A'}\inB{B}\inC{C_{\text{in}}'} \\ &\quad + \inA{A}\inB{B'}\inC{C_{\text{in}}'} + \inA{A}\inB{B}\inC{C_{\text{in}}} \\ &= (\inA{A} \oplus \inB{B}) \oplus \inC{C_{\text{in}}} \end{aligned}
5

The Ripple-Carry Adder

A single Full Adder handles one column of binary addition. To add two four-bit binary numbers A3A2A1A0+B3B2B1B0\inA{A_3A_2A_1A_0} + \inB{B_3B_2B_1B_0}, we chain four Full Adders from right to left so each column's Cout\carry{C_{\text{out}}} wire feeds directly into the next column's Cin\inC{C_{\text{in}}}.

The Ripple-Carry Adder
A30B30\begin{array}{c}\htmlClass{lc-blue}{A_3} \\ \htmlClass{lc-blue}{0} \\[5pt] \htmlClass{lc-pink}{B_3} \\ \htmlClass{lc-pink}{0}\end{array}
A21B20\begin{array}{c}\htmlClass{lc-blue}{A_2} \\ \htmlClass{lc-blue}{1} \\[5pt] \htmlClass{lc-pink}{B_2} \\ \htmlClass{lc-pink}{0}\end{array}
A10B11\begin{array}{c}\htmlClass{lc-blue}{A_1} \\ \htmlClass{lc-blue}{0} \\[5pt] \htmlClass{lc-pink}{B_1} \\ \htmlClass{lc-pink}{1}\end{array}
A01    (5)B01    (3)\begin{array}{c}\htmlClass{lc-blue}{A_0} \\ \htmlClass{lc-blue}{1}\mathrlap{\;\;(5)} \\[5pt] \htmlClass{lc-pink}{B_0} \\ \htmlClass{lc-pink}{1}\mathrlap{\;\;(3)}\end{array}
++
FA3\text{FA3}
FA2\text{FA2}
FA1\text{FA1}
FA0\text{FA0}
Text solution
Add the ones column at FA0\text{FA0} with Cin=0\inC{C_{\text{in}}} = \carry{0}To add 01012\inA{0101_2} (55) and 00112\inB{0011_2} (33), the rightmost box has no previous column, so it adds A0=1\inA{A_0} = \inA{1} and B0=1\inB{B_0} = \inB{1} with Cin=0\inC{C_{\text{in}}} = \carry{0}:
1+1+0=102  ⟹  Cout=1,S0=0\displaystyle \begin{aligned} \inA{1} + \inB{1} + \carry{0} &= \carry{1}\sumbit{0}_2 \\ &\implies \carry{C_{\text{out}}} = \carry{1}, \\ &\qquad \sumbit{S_0} = \sumbit{0} \end{aligned}
Pass each carry left through FA1\text{FA1} and FA2\text{FA2}Each middle box adds its column's two bits plus the Cout=1\carry{C_{\text{out}}} = \carry{1} arriving from the box to its right:
FA1 (twos):0+1+1=102  ⟹  Cout=1,S1=0FA2 (fours):1+0+1=102  ⟹  Cout=1,S2=0\displaystyle \begin{aligned} \text{FA1 (twos):} \\ \inA{0} + \inB{1} + \carry{1} &= \carry{1}\sumbit{0}_2 \\ &\implies \carry{C_{\text{out}}} = \carry{1}, \\ &\qquad \sumbit{S_1} = \sumbit{0} \\ \text{FA2 (fours):} \\ \inA{1} + \inB{0} + \carry{1} &= \carry{1}\sumbit{0}_2 \\ &\implies \carry{C_{\text{out}}} = \carry{1}, \\ &\qquad \sumbit{S_2} = \sumbit{0} \end{aligned}
Finish at FA3\text{FA3} and read the four sum wiresThe eights column adds A3=0\inA{A_3} = \inA{0}, B3=0\inB{B_3} = \inB{0}, and the incoming carry 1\carry{1} to complete the four-bit answer S3S2S1S0=10002\sumbit{S_3S_2S_1S_0} = \sumbit{1000_2} (88):
FA3 (eights):0+0+1=012  ⟹  Cout=0,S3=1\displaystyle \begin{aligned} \text{FA3 (eights):} \\ \inA{0} + \inB{0} + \carry{1} &= \carry{0}\sumbit{1}_2 \\ &\implies \carry{C_{\text{out}}} = \carry{0}, \\ &\qquad \sumbit{S_3} = \sumbit{1} \end{aligned}

Because each Full Adder waits for the previous column's Cout\carry{C_{\text{out}}} before its own Cin\inC{C_{\text{in}}} is known, a single carry generated at FA0\text{FA0} on the right can ripple step by step through every box to FA3\text{FA3} on the left.

Each Full Adder waits on the carry wire from the column to its right, so changing a single bit in the ones place can ripple across all four columns.
6

Universal Gates: NAND and NOR

We have built every circuit so far from AND, OR, and NOT gates, and now we want to see how to build any circuit using only a single type of gate: either all NAND gates (an AND gate with a NOT bubble at the tip, outputting (AB)′(\inA{A}\inB{B})') or all NOR gates (an OR gate with a NOT bubble at the tip, outputting (A+B)′(\inA{A} + \inB{B})').

When a prime covers a product or a sum, De Morgan's Laws break the prime across the two inputs and swap AND with OR:

(X⋅Y)′=X′+Y′,(X+Y)′=X′⋅Y′\displaystyle \begin{aligned} (\inA{X} \cdot \inB{Y})' &= \inA{X'} + \inB{Y'}, \\ (\inA{X} + \inB{Y})' &= \inA{X'} \cdot \inB{Y'} \end{aligned}
Universal Gates: NAND and NOR
NAND\text{NAND}
NOT\text{NOT}
AND\text{AND}
OR\text{OR}
NOR\text{NOR}
NOT\text{NOT}
OR\text{OR}
AND\text{AND}
NAND-NOT\text{NAND-NOT}
A\htmlClass{lc-blue}{A}
A′\htmlClass{lc-blue}{A'}
NOR-NOT\text{NOR-NOT}
A\htmlClass{lc-blue}{A}
A′\htmlClass{lc-blue}{A'}
NAND-AND\text{NAND-AND}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
(AB)′(\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B})'
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
NOR-OR\text{NOR-OR}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
(A+B)′(\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B})'
A+B\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B}
NAND-OR\text{NAND-OR}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
A′\htmlClass{lc-blue}{A'}
B′\htmlClass{lc-pink}{B'}
A+B\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B}
NOR-AND\text{NOR-AND}
A\htmlClass{lc-blue}{A}
B\htmlClass{lc-pink}{B}
A′\htmlClass{lc-blue}{A'}
B′\htmlClass{lc-pink}{B'}
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
Text solution
Tie both inputs together to make a NOT gate (1 gate)Splitting wire A\inA{A} into both inputs of a single NAND or NOR gate applies A⋅A=A\inA{A} \cdot \inA{A} = \inA{A} or A+A=A\inA{A} + \inA{A} = \inA{A} before the bubble flips it:
NAND-NOT:(A⋅A)′=A′,NOR-NOT:(A+A)′=A′\displaystyle \begin{aligned} \text{NAND-NOT:}\quad (\inA{A} \cdot \inA{A})' &= \inA{A'}, \\ \text{NOR-NOT:}\quad (\inA{A} + \inA{A})' &= \inA{A'} \end{aligned}
Place a 1-gate NOT after the gate to undo its bubble (2 gates)A NAND gate already computes AND with an extra flip, and a NOR gate already computes OR with an extra flip, so adding one inverter at the output restores the original operation:
NAND-AND:((AB)′)′=AB,NOR-OR:((A+B)′)′=A+B\displaystyle \begin{aligned} \text{NAND-AND:}\quad ((\inA{A}\inB{B})')' &= \inA{A}\inB{B}, \\ \text{NOR-OR:}\quad ((\inA{A} + \inB{B})')' &= \inA{A} + \inB{B} \end{aligned}
Invert both inputs first to swap AND and OR by De Morgan's Law (3 gates)Feeding A′\inA{A'} and B′\inB{B'} into a final NAND or NOR gate breaks the outer flip across the inputs and swaps the operation:
NAND-OR:(A′⋅B′)′=A′′+B′′=A+BNOR-AND:(A′+B′)′=A′′⋅B′′=AB\displaystyle \begin{aligned} \text{NAND-OR:} \\ (\inA{A'} \cdot \inB{B'})' &= \inA{A''} + \inB{B''} \\ &= \inA{A} + \inB{B} \\ \text{NOR-AND:} \\ (\inA{A'} + \inB{B'})' &= \inA{A''} \cdot \inB{B''} \\ &= \inA{A}\inB{B} \end{aligned}

Flipping the inputs first turns the final NAND gate into an OR gate and the final NOR gate into an AND gate.

Flipping the inputs before a NAND gate makes it act like an OR gate, and flipping the inputs before a NOR gate makes it act like an AND gate.

Key concepts

To move between diagrams and algebra, label wires from left to right when reading a circuit, and work from inside the parentheses outward when drawing one. Pay close attention to what a prime covers: A′B\inA{A'}\inB{B} puts a NOT gate on wire A\inA{A} before the AND gate, whereas (AB)′(\inA{A}\inB{B})' puts the NOT gate after the AND gate. When you start from a truth table instead of a formula, write an AND minterm for each row where Output=1\text{Output} = \one{1} (putting a prime on any 0\zero{0} input, like A′BC\inA{A'}\inB{B}\inC{C} for 0,1,1\zero{0}, \one{1}, \one{1}) and OR them into a two-layer AND-OR circuit. Before building the full minterm gates, check whether any two minterms differ in only one variable, such as A′BC+ABC\flips{A'}\inB{B}\inC{C} + \flips{A}\inB{B}\inC{C} == BC\inB{B}\inC{C}, so you can drop the changing variable and use smaller gates.

For binary addition, use a two-input Half Adder (Sum=A⊕B\text{Sum} = \inA{A} \oplus \inB{B}, Carry=AB\text{Carry} = \inA{A}\inB{B}) only when there is no incoming carry, such as the ones column on the far right. Any column that receives a carry Cin\inC{C_{\text{in}}} needs a three-input Full Adder, where Sum=(A⊕B)⊕Cin\text{Sum} = (\inA{A} \oplus \inB{B}) \oplus \inC{C_{\text{in}}} turns on for an odd number of 1\one{1}s (11 or 33) and CoutC_{\text{out}} == AB+BCin+ACin\inA{A}\inB{B} + \inB{B}\inC{C_{\text{in}}} + \inA{A}\inC{C_{\text{in}}} turns on for at least two 1\one{1}s (22 or 33). When replacing gates with universal NAND or NOR blocks, tie both inputs together for a 1-gate NOT ((A⋅A)′=A′(\inA{A} \cdot \inA{A})' = \inA{A'}), invert the output to keep the base operation (((AB)′)′=AB((\inA{A}\inB{B})')' = \inA{A}\inB{B}), and invert the inputs to swap operations ((A′⋅B′)′=A+B(\inA{A'} \cdot \inB{B'})' = \inA{A} + \inB{B} and (A′+B′)′=AB(\inA{A'} + \inB{B'})' = \inA{A}\inB{B}). Don't blindly insert an input inverter if a wire is already primed: in A+B′\inA{A} + \inB{B'} == (A′⋅B′′)′(\inA{A'} \cdot \cancels{B''})' == (A′⋅B)′(\inA{A'} \cdot \inB{B})', the double inversion on B\inB{B} cancels out so wire B\inB{B} plugs straight into the final NAND gate.

7

Practice

1

In a circuit with inputs A\inA{A}, B\inB{B}, and C\inC{C}, wire A\inA{A} passes through a NOT gate, and its output feeds along with wire B\inB{B} into an OR gate. The output of that OR gate passes through a second NOT gate. Finally, the output of that second NOT gate and wire C\inC{C} feed into an AND gate, whose output passes through a third NOT gate. Write the Boolean expression for each wire from left to right and the final output.

Label one wire at a time from left to right; whenever a wire comes out of an OR or AND gate and enters a NOT gate, what must go around that sub-expression before you write the prime?

Wire A\inA{A} after the first NOT gate is A′\inA{A'}. After the OR gate with B\inB{B}, the wire is A′+B\inA{A'} + \inB{B}. After the second NOT gate, the wire is (A′+B)′(\inA{A'} + \inB{B})'. Be careful not to leave off the parentheses and write A′+B′\inA{A'} + \inB{B'}, because the NOT gate flips the entire OR output wire, not just B\inB{B}. After the AND gate with C\inC{C}, the wire is (A′+B)′C(\inA{A'} + \inB{B})'\inC{C}. After the third NOT gate, enclosing the whole AND output in parentheses before flipping gives the final output ((A′+B)′C)′((\inA{A'} + \inB{B})'\inC{C})'.
2

To build a circuit for the expression (A′B+C)′(\inA{A'}\inB{B} + \inC{C})', in what order do you connect the gates from the input wires outward, and what is the output of the circuit when A=1\inA{A} = \one{1}, B=1\inB{B} = \one{1}, and C=0\inC{C} = \zero{0}?

Start with the innermost operation inside the parentheses: which single letter has a prime on it before the AND product A′B\inA{A'}\inB{B} is formed?

Work from the inside of the parentheses outward: (1) pass wire A\inA{A} through a NOT gate to get A′\inA{A'} (don't put the NOT gate after the AND gate, which would build (AB)′(\inA{A}\inB{B})' instead of A′B\inA{A'}\inB{B}); (2) feed A′\inA{A'} and B\inB{B} into an AND gate to get A′B\inA{A'}\inB{B}; (3) feed the A′B\inA{A'}\inB{B} wire and wire C\inC{C} into an OR gate to get A′B+C\inA{A'}\inB{B} + \inC{C}; (4) pass the OR gate's output through a NOT gate to get (A′B+C)′(\inA{A'}\inB{B} + \inC{C})'.
When A=1\inA{A} = \one{1}, B=1\inB{B} = \one{1}, and C=0\inC{C} = \zero{0}, we have A′=0\inA{A'} = \zero{0}, A′B=0⋅1=0\inA{A'}\inB{B} = \zero{0} \cdot \one{1} = \zero{0}, and A′B+C=0+0=0\inA{A'}\inB{B} + \inC{C} = \zero{0} + \zero{0} = \zero{0}. Don't stop at the OR gate and answer 0\zero{0}; applying the final outer NOT gate gives Output=0′=1\text{Output} = \zero{0}' = \one{1}.
3

A factory alarm (Output=1\text{Output} = \one{1}) must sound whenever Sensor A\inA{A} is on (1\one{1}) and at least one of Sensors B\inB{B} and C\inC{C} is off (0\zero{0}). Write the Sum of Products expression from the truth table, describe the two-layer AND-OR circuit it builds, and then simplify the expression by combining minterms that differ in only one variable.

List the three truth-table rows where A=1\inA{A} = \one{1} and (B,C)(\inB{B}, \inC{C}) is not (1,1)(\one{1}, \one{1}); once you write the three minterms, notice which minterm differs in only one variable from both of the others so you can pair it with each of them.

The rows with A=1\inA{A} = \one{1} and at least one of B,C\inB{B}, \inC{C} equal to 0\zero{0} are (1,0,0)(\one{1}, \zero{0}, \zero{0}), (1,0,1)(\one{1}, \zero{0}, \one{1}), and (1,1,0)(\one{1}, \one{1}, \zero{0}), giving the Sum of Products expression:
Output\displaystyle \text{Output} =AB′C′+AB′C+ABC′\displaystyle = \inA{A}\inB{B'}\inC{C'} + \inA{A}\inB{B'}\inC{C} + \inA{A}\inB{B}\inC{C'}
The two-layer Sum of Products circuit uses two NOT gates (for the B′\inB{B'} and C′\inC{C'} wires) and three 3-input AND gates feeding into one 3-input OR gate.
To simplify the expression, pair AB′C′+AB′C\inA{A}\inB{B'}\flips{C'} + \inA{A}\inB{B'}\flips{C} == AB′(C′+C)\inA{A}\inB{B'}(\flips{C'} + \flips{C}) == AB′\inA{A}\inB{B'}. Don't stop after using AB′C′\inA{A}\inB{B'}\inC{C'} once, which would leave AB′+ABC′\inA{A}\inB{B'} + \inA{A}\inB{B}\inC{C'}. Because X+X=XX + X = X, we can reuse AB′C′\inA{A}\inB{B'}\inC{C'} to pair with ABC′\inA{A}\inB{B}\inC{C'} as well, giving AB′C′+ABC′\inA{A}\flips{B'}\inC{C'} + \inA{A}\flips{B}\inC{C'} == A(B′+B)C′\inA{A}(\flips{B'} + \flips{B})\inC{C'} == AC′\inA{A}\inC{C'} and reducing the circuit to two 2-input AND gates feeding one 2-input OR gate:
Output\displaystyle \text{Output} =AB′+AC′\displaystyle = \inA{A}\inB{B'} + \inA{A}\inC{C'}
4

A Full Adder is built from two Half Adders and an OR gate: the first Half Adder adds A\inA{A} and B\inB{B} to give partial sum S1=A⊕BS_1 = \inA{A} \oplus \inB{B} and carry C1=ABC_1 = \inA{A}\inB{B}; the second Half Adder adds S1S_1 and Cin\inC{C_{\text{in}}} to give the final Sum=S1⊕Cin\text{Sum} = S_1 \oplus \inC{C_{\text{in}}} and carry C2=S1CinC_2 = S_1 \inC{C_{\text{in}}}; and the OR gate combines C1C_1 and C2C_2 into CoutC_{\text{out}}. Find S1S_1, C1C_1, C2C_2, Sum\text{Sum}, and CoutC_{\text{out}} when (a) A=1\inA{A} = \one{1}, B=1\inB{B} = \one{1}, Cin=0\inC{C_{\text{in}}} = \zero{0} and (b) A=1\inA{A} = \one{1}, B=0\inB{B} = \zero{0}, Cin=1\inC{C_{\text{in}}} = \one{1}. Can C1C_1 and C2C_2 ever both be 1\one{1} at the same time?

Remember that an XOR gate (⊕\oplus) outputs 0\zero{0} when both of its inputs are 1\one{1}; for the last question, trace what C1=1C_1 = \one{1} forces A\inA{A}, B\inB{B}, and therefore S1S_1 to be.

Be careful not to treat ⊕\oplus like a regular OR gate when both inputs are 1\one{1} (1⊕1=0\one{1} \oplus \one{1} = \zero{0}, not 1\one{1}). (a) For A=1\inA{A} = \one{1}, B=1\inB{B} = \one{1}, Cin=0\inC{C_{\text{in}}} = \zero{0}: S1=1⊕1=0S_1 = \one{1} \oplus \one{1} = \zero{0}, C1=1⋅1=1C_1 = \one{1} \cdot \one{1} = \one{1}, C2=0⋅0=0C_2 = \zero{0} \cdot \zero{0} = \zero{0}, Sum=0⊕0=0\text{Sum} = \zero{0} \oplus \zero{0} = \zero{0}, and Cout=1+0=1C_{\text{out}} = \one{1} + \zero{0} = \one{1}. (b) For A=1\inA{A} = \one{1}, B=0\inB{B} = \zero{0}, Cin=1\inC{C_{\text{in}}} = \one{1}: S1=1⊕0=1S_1 = \one{1} \oplus \zero{0} = \one{1}, C1=1⋅0=0C_1 = \one{1} \cdot \zero{0} = \zero{0}, C2=1⋅1=1C_2 = \one{1} \cdot \one{1} = \one{1}, Sum=1⊕1=0\text{Sum} = \one{1} \oplus \one{1} = \zero{0}, and Cout=0+1=1C_{\text{out}} = \zero{0} + \one{1} = \one{1}.
C1C_1 and C2C_2 can never both be 1\one{1} at the same time: if C1=AB=1C_1 = \inA{A}\inB{B} = \one{1}, then A=1\inA{A} = \one{1} and B=1\inB{B} = \one{1}, which forces S1=A⊕B=0S_1 = \inA{A} \oplus \inB{B} = \zero{0} and therefore C2=S1Cin=0C_2 = S_1 \inC{C_{\text{in}}} = \zero{0}.
5

Trace a 4-bit Ripple-Carry Adder (FA0\text{FA0} through FA3\text{FA3}, with Cin=0\inC{C_{\text{in}}} = \carry{0} at FA0\text{FA0}) when adding A=01102\inA{A} = \inA{0110_2} (66) and B=01112\inB{B} = \inB{0111_2} (77). For each Full Adder from right to left, list its inputs (Ai,Bi,Cin)(\inA{A_i}, \inB{B_i}, \inC{C_{\text{in}}}) and outputs (Si,Cout)(\sumbit{S_i}, \carry{C_{\text{out}}}), and state the final 4-bit sum S3S2S1S0\sumbit{S_3S_2S_1S_0}.

Start at FA0\text{FA0} with the rightmost bits A0=0\inA{A_0} = \inA{0} and B0=1\inB{B_0} = \inB{1}, and pass each box's Cout\carry{C_{\text{out}}} into the next box's Cin\inC{C_{\text{in}}}.

Working column by column from right to left:
FA0\text{FA0} gets (A0=0,B0=1,Cin=0)(\inA{A_0} = \inA{0}, \inB{B_0} = \inB{1}, \inC{C_{\text{in}}} = \carry{0}) and outputs S0=1,Cout=0\sumbit{S_0} = \sumbit{1}, \carry{C_{\text{out}}} = \carry{0}.
FA1\text{FA1} gets (A1=1,B1=1,Cin=0)(\inA{A_1} = \inA{1}, \inB{B_1} = \inB{1}, \inC{C_{\text{in}}} = \carry{0}) and outputs S1=0,Cout=1\sumbit{S_1} = \sumbit{0}, \carry{C_{\text{out}}} = \carry{1}.
FA2\text{FA2} gets (A2=1,B2=1,Cin=1)(\inA{A_2} = \inA{1}, \inB{B_2} = \inB{1}, \inC{C_{\text{in}}} = \carry{1}). Here all three inputs are 11, giving a total of 3=1123 = \carry{1}\sumbit{1}_2, so don't confuse it with 1+1=1021 + 1 = 10_2 and write S2=0S_2 = 0; it outputs S2=1,Cout=1\sumbit{S_2} = \sumbit{1}, \carry{C_{\text{out}}} = \carry{1}.
FA3\text{FA3} gets (A3=0,B3=0,Cin=1)(\inA{A_3} = \inA{0}, \inB{B_3} = \inB{0}, \inC{C_{\text{in}}} = \carry{1}) and outputs S3=1,Cout=0\sumbit{S_3} = \sumbit{1}, \carry{C_{\text{out}}} = \carry{0}.
The final 4-bit sum is S3S2S1S0=11012\sumbit{S_3S_2S_1S_0} = \sumbit{1101_2} (1313).
6

Build a circuit for Output=A+B′\text{Output} = \inA{A} + \inB{B'} using only 2-input NAND gates. How many NAND gates does a direct substitution of the NAND-NOT and 3-NAND OR circuits take, and what is the smallest number of NAND gates needed once you remove back-to-back inversions?

Write the 3-NAND OR formula X+Y=(X′⋅Y′)′\inA{X} + \inB{Y} = (\inA{X'} \cdot \inB{Y'})' with X=A\inA{X} = \inA{A} and Y=B′\inB{Y} = \inB{B'}; what happens to the two primes on B\inB{B}?

A direct substitution uses 11 NAND-NOT gate to make B′\inB{B'} and 33 NAND gates for the OR gate, totaling 4\howmany{4} NAND gates. However, don't leave two NAND-NOT gates in a row on wire B\inB{B}: since the 3-NAND OR circuit inverts both of its inputs to compute X+Y=(X′⋅Y′)′\inA{X} + \inB{Y} = (\inA{X'} \cdot \inB{Y'})', setting X=A\inA{X} = \inA{A} and Y=B′\inB{Y} = \inB{B'} gives:
A+B′\displaystyle \inA{A} + \inB{B'} =(A′⋅B′′)′\displaystyle = (\inA{A'} \cdot \cancels{B''})' =(A′⋅B)′\displaystyle = (\inA{A'} \cdot \inB{B})'
Canceling B′′=B\cancels{B''} = \inB{B} leaves just 2\howmany{2} NAND gates: tie both inputs of the first NAND gate to A\inA{A} to get A′=(A⋅A)′\inA{A'} = (\inA{A} \cdot \inA{A})', and feed A′\inA{A'} and B\inB{B} into a second NAND gate to get ((A⋅A)′⋅B)′((\inA{A} \cdot \inA{A})' \cdot \inB{B})'.
7

Build a circuit for Output=(A+B)C′\text{Output} = (\inA{A} + \inB{B})\inC{C'} using only 2-input NOR gates in as few gates as possible, and write the nested NOR expression it computes.

Rewrite the outer AND product using the NOR-AND rule X⋅Y=(X′+Y′)′\inA{X} \cdot \inB{Y} = (\inA{X'} + \inB{Y'})' with X=A+B\inA{X} = \inA{A} + \inB{B} and Y=C′\inB{Y} = \inC{C'} before building any gates.

Don't build each piece separately by direct substitution (22 NOR gates for A+B\inA{A} + \inB{B}, 11 NOR gate for C′\inC{C'}, and 33 NOR gates for the AND gate, which uses 66 gates). Instead, applying the NOR-AND rule X⋅Y=(X′+Y′)′\inA{X} \cdot \inB{Y} = (\inA{X'} + \inB{Y'})' with X=A+B\inA{X} = \inA{A} + \inB{B} and Y=C′\inB{Y} = \inC{C'} cancels the extra inversions on both inputs at once:
(A+B)C′\displaystyle (\inA{A} + \inB{B})\inC{C'} =((A+B)′+C′′)′\displaystyle = ((\inA{A} + \inB{B})' + \cancels{C''})' =((A+B)′+C)′\displaystyle = ((\inA{A} + \inB{B})' + \inC{C})'
This requires only 2\howmany{2} NOR gates: feed A\inA{A} and B\inB{B} into the first NOR gate to get (A+B)′(\inA{A} + \inB{B})', and feed that wire along with C\inC{C} into a second NOR gate to compute ((A+B)′+C)′((\inA{A} + \inB{B})' + \inC{C})'.