Skip to content
Ahmet Çelik

Chapter 4: Combinational Logic Circuits

ELEC205 12 minute read

Source files used: ELEC205 Week 3 slides (slides 40-46), Week 5 slides (slides 16-44), Week 6 slides; textbook Chapter 4 as support. No worked examples are included.

1. Big Picture

Chapter 4 is the standard “plays” built from gates: adders, decoders, encoders, multiplexers.

Chapters 2 and 3 asked: how do we build and minimize one function? Chapter 4 asks: what are the reusable building blocks, and how do we design any function with them?

Analyze or design a combinational circuit using XOR, adders, decoders, encoders and MUXes.\boxed{\text{Analyze or design a combinational circuit using XOR, adders, decoders, encoders and MUXes.}}

New ideas in this chapter:

  • XOR/XNOR as odd/even functions and parity,
  • half adder, full adder, ripple-carry adder,
  • 2’s complement adder/subtractor and overflow detection,
  • decoders (and implementing functions with them),
  • encoders and priority encoders,
  • multiplexers (and implementing functions with them), demultiplexers.

Erzin groups the blocks by job: decoding, encoding, selecting.


2. Core Ideas

2.1 Analysis vs Design

Analysis: given a circuit, find what it does.

  • exhaustive (truth table),
  • algebraic (expressions),
  • simulation / test bench (HDL description, test vectors, compare with a known-good model).

Design: given a specification, build the circuit. Either write the equations directly from “logic”, or brute-force it: truth table → canonical sum → minimize (Chapter 3).


2.2 XOR: The Odd Function

X⊕YX\oplus Y is 1 when the inputs differ. A multi-input XOR is 1 when an odd number of inputs are 1 (sum modulo 2). XNOR is the even function.

The K-map of a 3- or 4-input XOR is a checkerboard: no two 1’s are adjacent, so it cannot be simplified as SOP. That is why XOR gets its own gate.


2.3 Parity

Multi-input XOR computes parity. A chain of 2-input XORs works but has a long delay line. A parity tree (balanced XOR tree) gives the same result with less delay.


2.4 Building Wide Adders

A 32-bit adder is a 64-input, 33-output combinational system. Its truth table is impossible to write, so it is built from 1-bit cells: a half adder (or a full adder with Cin=0C_{in}=0) at bit 0 and full adders above, with each carry feeding the next stage. Two 32-bit adders cascade into a 64-bit adder by connecting CoutC_{out} of the low half to CinC_{in} of the high half.


2.5 Subtraction with an Adder

In 2’s complement, A−B=A+(−B)=A+B′+1A-B=A+(-B)=A+B'+1. Invert every bit of BB and set the LSB carry-in to 1. No separate subtractor is needed.


2.6 Decoders

A decoder maps an nn-bit code to 2n2^n output lines. With enable on, exactly one output is 1: output kk is minterm mkm_k of the inputs. With enable off, all outputs are 0.

Applications: selecting memory banks or I/O devices, instruction decoding, memory row selection, seven-segment (4-to-7) decoding.


2.7 Encoders and Priority

An encoder is the reverse of a decoder: 2n2^n inputs to an nn-bit code. A plain encoder assumes exactly one input is active. If two inputs are active, or none, it gives a wrong or ambiguous code.

A priority encoder fixes this: the highest-priority active input wins, lower inputs become don’t-cares, and a valid output VV says whether any input is active.


2.8 Multiplexers

A MUX selects one of many inputs and sends it to a single output. With nn select bits it has 2n2^n data inputs (2n2^n-to-1 MUX). A demultiplexer (DMUX) is the inverse: one input routed to one of 2n2^n outputs. A 1-to-4 DMUX is the same circuit as a 2-to-4 decoder with enable, with the enable used as the data input.


3. Main Governing Equations and Formulas

3.1 XOR Identities

X⊕Y=XY′+X′YX\oplus Y=XY'+X'Y X⊕0=XX⊕1=X′X⊕X=0X\oplus0=X\qquad X\oplus1=X'\qquad X\oplus X=0 X⊕Y=Y⊕X(X⊕Y)⊕Z=X⊕(Y⊕Z)=X⊕Y⊕ZX\oplus Y=Y\oplus X\qquad (X\oplus Y)\oplus Z=X\oplus(Y\oplus Z)=X\oplus Y\oplus Z

X⊕1=X′X\oplus1=X' is why an XOR works as a controlled inverter (used in the adder/subtractor).


3.2 XOR with Four NAND Gates

F=[((XY)′⋅X)′⋅((XY)′⋅Y)′]′=XY′+X′YF=\big[((XY)'\cdot X)'\cdot((XY)'\cdot Y)'\big]'=XY'+X'Y

One shared NAND makes (XY)′(XY)', two NANDs combine it with XX and YY, one output NAND.


3.3 Half Adder

S=A⊕B,C=ABS=A\oplus B,\qquad C=AB

Adds two bits with no carry-in. One XOR and one AND.


3.4 Full Adder

S=A⊕B⊕CinS=A\oplus B\oplus C_{in} Co=AB+Cin(A⊕B)C_o=AB+C_{in}(A\oplus B)

Built from two half adders plus an OR gate: the first HA makes A⊕BA\oplus B and ABAB, the second adds CinC_{in}, the OR combines the two carries.


3.5 Ripple-Carry Adder

Si=Ai⊕Bi⊕Ci,Ci+1=AiBi+Ci(Ai⊕Bi)S_i=A_i\oplus B_i\oplus C_i,\qquad C_{i+1}=A_iB_i+C_i(A_i\oplus B_i)

Bit 0 is on the right; the carry ripples right to left. nn full adders make an nn-bit adder, and the final carry is CnC_n.


3.6 Adder/Subtractor

Each BiB_i passes through an XOR with a control line SS; SS also drives C0C_0:

Bi∗=Bi⊕S,C0=SB_i^{*}=B_i\oplus S,\qquad C_0=S S=0: A+BS=1: A+B′+1=A−BS=0:\ A+B\qquad\qquad S=1:\ A+B'+1=A-B

Use for any “add or subtract with one circuit” question (slide Fig. 3-31).


3.7 Overflow Detection

For an nn-bit 2’s complement adder/subtractor:

V=Cn⊕Cn−1V=C_n\oplus C_{n-1}

where CnC_n is the carry out of the MSB and Cn−1C_{n-1} is the carry into the MSB. V=1V=1 means overflow.

Slide examples (4 bits, range [−8,7][-8,7]): +5+7+5+7 has carries 01110111, so C4⊕C3=1C_4\oplus C_3=1: overflow. −4−6-4-6 has carries 10001000: overflow. +5+2+5+2 and −4−3-4-3 have equal last two carries: no overflow.

CC (the carry out itself) is the overflow indicator for unsigned numbers; VV is the one for signed numbers.


3.8 Decoder Outputs

For a 2-to-4 decoder with enable ENEN:

D0=I1′I0′ EN,D1=I1′I0 EN,D2=I1I0′ EN,D3=I1I0 END_0=I_1'I_0'\,EN,\quad D_1=I_1'I_0\,EN,\quad D_2=I_1I_0'\,EN,\quad D_3=I_1I_0\,EN

In general:

Dk=mk⋅END_k=m_k\cdot EN

3.9 Decoder Expansion

3-to-8 from two 2-to-4 decoders with enable:

ENlow=A2′,ENhigh=A2EN_{\text{low}}=A_2',\qquad EN_{\text{high}}=A_2

A1A0A_1A_0 go to both decoders. The upper decoder produces D0D_0-D3D_3 (A2=0A_2=0), the lower produces D4D_4-D7D_7 (A2=1A_2=1). With an overall enable, AND it into both enables.


3.10 Function from Decoder + OR

F=∑m(k1,k2,… )=Dk1+Dk2+…F=\sum m(k_1,k_2,\dots)=D_{k_1}+D_{k_2}+\dots

An nn-to-2n2^n decoder generates every minterm, so any nn-variable function (or several functions at once) needs only one OR gate per output. Use when a question says “decoder and external OR gates”.


3.11 Binary Encoder (8-to-3)

A0=D1+D3+D5+D7A_0=D_1+D_3+D_5+D_7 A1=D2+D3+D6+D7A_1=D_2+D_3+D_6+D_7 A2=D4+D5+D6+D7A_2=D_4+D_5+D_6+D_7

Each output bit ORs the inputs whose index has that bit set. Valid only if exactly one input is 1.


3.12 4-to-2 Priority Encoder

Priority D3>D2>D1>D0D_3>D_2>D_1>D_0:

A1=D3+D2A_1=D_3+D_2 A0=D3+D2′D1A_0=D_3+D_2'D_1 V=D0+D1+D2+D3V=D_0+D_1+D_2+D_3

When V=0V=0 (no input active), A1A0A_1A_0 are don’t-cares. Derived from K-maps of Table 3-6 using the don’t-cares.


3.13 8-to-3 Priority Encoder from Two 4-to-2s

Let encoder A take D0D_0-D3D_3 (outputs A1,A0,VAA_1,A_0,V_A) and encoder B take D4D_4-D7D_7 (outputs B1,B0,VBB_1,B_0,V_B). The upper group has priority:

C2=VBC_2=V_B C1=VB′A1+VBB1,C0=VB′A0+VBB0C_1=V_B'A_1+V_BB_1,\qquad C_0=V_B'A_0+V_BB_0 VC=VA+VBV_C=V_A+V_B

VBV_B acts as the select of two 2-to-1 MUXes.


3.14 4-to-1 MUX

Y=S1′S0′D0+S1′S0D1+S1S0′D2+S1S0D3Y=S_1'S_0'D_0+S_1'S_0D_1+S_1S_0'D_2+S_1S_0D_3

Each term is a select minterm ANDed with its data input. In general, a 2n2^n-to-1 MUX outputs Y=∑kmk(S) DkY=\sum_k m_k(S)\,D_k. A quadruple 2-to-1 MUX is four 2-to-1 MUXes sharing one select line (selects a 4-bit word).


3.15 Function from a MUX

An nn-variable function fits a 2n−12^{n-1}-to-1 MUX. Put the first n−1n-1 variables on the selects; each data input becomes one of

Dk∈{0, 1, Z, Z′}D_k\in\{0,\ 1,\ Z,\ Z'\}

where ZZ is the last variable. This is the Shannon expansion applied to the select variables.

Slide example: F(X,Y,Z)=∑m(1,2,6,7)F(X,Y,Z)=\sum m(1,2,6,7) with S1=XS_1=X, S0=YS_0=Y gives D0=ZD_0=Z, D1=Z′D_1=Z', D2=0D_2=0, D3=1D_3=1.

Slide example: F(A,B,C,D)=∑m(1,3,4,11,12,13,14,15)F(A,B,C,D)=\sum m(1,3,4,11,12,13,14,15) on an 8-to-1 MUX with S2S1S0=ABCS_2S_1S_0=ABC gives D0=DD_0=D, D1=DD_1=D, D2=D′D_2=D', D3=0D_3=0, D4=0D_4=0, D5=DD_5=D, D6=1D_6=1, D7=1D_7=1.


4. Problem-Solving Workflow

4.1 Implementing FF with a 2n−12^{n-1}-to-1 MUX

  1. Write the truth table with the select variables as the leading (most significant) columns.
  2. Split the rows into pairs that share the same select values.
  3. In each pair, compare FF with the last variable:
    • F=0,0F=0,0 → Dk=0D_k=0,
    • F=1,1F=1,1 → Dk=1D_k=1,
    • FF equals the last variable → Dk=ZD_k=Z,
    • FF is its complement → Dk=Z′D_k=Z'.
  4. Connect, making sure S0S_0 is the least significant select variable.

4.2 Implementing FF with a Decoder

  1. Express each output as ∑m(… )\sum m(\dots) (expand terms to minterms if given as an expression).
  2. Use an nn-to-2n2^n decoder on the nn inputs.
  3. OR the decoder outputs listed in each function.
  4. If a function has many minterms, OR the outputs of F′F' and invert (NOR), which needs fewer inputs (textbook tip).

4.3 Designing a Priority Encoder

  1. Write the condensed truth table (inputs below the highest active one are X).
  2. Plot each output on a K-map, filling X rows as don’t-cares.
  3. Minimize each output; add VV as the OR of all inputs.

4.4 Adder/Subtractor Questions

  1. Choose the control: S=0S=0 add, S=1S=1 subtract.
  2. XOR each BiB_i with SS; set C0=SC_0=S.
  3. Ripple through the full adders.
  4. Check overflow with V=Cn⊕Cn−1V=C_n\oplus C_{n-1}.

5. Decision Rules / Decision Trees

5.1 Which Building Block?

Need exactly one of 2n2^n lines active from an nn-bit code? → decoder

Need the index of the active line as a code? → encoder (priority encoder if several can be active)

Need to route one of many inputs to one output? → multiplexer

Need many functions of the same nn inputs? → one decoder + one OR per function

Need one function of nn inputs with a single block? → 2n−12^{n-1}-to-1 MUX

5.2 Overflow or Carry?

Operands are unsigned? → look at CC (carry out)

Operands are 2’s complement? → look at V=Cn⊕Cn−1V=C_n\oplus C_{n-1}

5.3 Priority Encoder Output

Highest active input is DiD_i? → output is ii in binary, lower inputs ignored, V=1V=1

No input active? → V=0V=0, outputs are don’t-care


6. Important Tables / Correlations Needed

6.1 Adder Truth Tables

AABBCinC_{in}CoC_oSS
00000
00101
01001
01110
10001
10110
11010
11111

The half adder is the first four rows with Cin=0C_{in}=0 (rows A,B=00,01,10,11A,B=00,01,10,11 give C,S=00,01,01,10C,S=00,01,01,10).

6.2 2-to-4 Decoder with Enable

ENENI1I_1I0I_0Y3Y_3Y2Y_2Y1Y_1Y0Y_0
0XX0000
1000001
1010010
1100100
1111000

6.3 4-to-2 Priority Encoder (Table 3-6)

D3D_3D2D_2D1D_1D0D_0A1A_1A0A_0VV
0000XX0
0001001
001X011
01XX101
1XXX111

6.4 Block Size Summary

BlockInputsOutputsControl
nn-to-2n2^n decodernn (+ enable)2n2^nenable
2n2^n-to-nn encoder2n2^nnn (+ VV if priority)none
2n2^n-to-1 MUX2n2^n data1nn select
1-to-2n2^n DMUX1 data2n2^nnn select

Slide quiz facts: a decoder with 2N2N inputs has at most 22N2^{2N} outputs; a priority encoder favoring higher indices with I3I2I1I0=0110I_3I_2I_1I_0=0110 outputs Y1Y0=10Y_1Y_0=10.


7. Key Takeaways

  • XOR is the odd function, XNOR the even function; their K-maps are checkerboards and cannot be simplified.
  • Half adder: S=A⊕BS=A\oplus B, C=ABC=AB. Full adder: S=A⊕B⊕CinS=A\oplus B\oplus C_{in}, Co=AB+Cin(A⊕B)C_o=AB+C_{in}(A\oplus B).
  • Subtraction: invert BB, set C0=1C_0=1; one XOR per bit makes an adder/subtractor.
  • Signed overflow: V=Cn⊕Cn−1V=C_n\oplus C_{n-1}; unsigned overflow: carry out CC.
  • Decoder output kk is minterm mkm_k; decoder + OR gates implement any function.
  • Expanding decoders: the extra MSB drives the enables (A2′A_2' and A2A_2).
  • Priority encoder (4-to-2): A1=D3+D2A_1=D_3+D_2, A0=D3+D2′D1A_0=D_3+D_2'D_1, V=V= OR of all inputs.
  • 4-to-1 MUX: Y=∑mk(S1S0)DkY=\sum m_k(S_1S_0)D_k.
  • nn-variable function on a 2n−12^{n-1}-to-1 MUX: data inputs are 00, 11, ZZ or Z′Z'.
  • Trap: check which variable goes to S0S_0 (LSB select); swapping selects scrambles the data inputs.