Introduction

Multiplexers (MUX), decoders and encoders are standard MSI combinational blocks. A MUX selects one of many data inputs using select lines. A decoder activates exactly one of 2n2^n outputs from an nn-bit code, so its outputs are the minterms of its inputs. An encoder (often a priority encoder) compresses one-hot or sparse inputs into a binary index.

GATE asks you to realize a Boolean function with a MUX (and find the data inputs), evaluate a cascade of MUXes, count the blocks in a MUX tree or decoder tree, realize several functions with one decoder plus OR gates, and write priority-encoder equations.

Prerequisites

Core concepts

Multiplexer

A 2n ⁣: ⁣12^n\!:\!1 MUX has 2n2^n data inputs I0..I2n−1I_0..I_{2^n-1}, nn select lines SS, and one output Y=ISY=I_S, where the select lines are read as a binary number. Enable (active low or high) may force Y=0Y=0 when disabled.

Boolean form. Y=∑kIk mk(S)Y=\sum_k I_k\, m_k(S) where mk(S)m_k(S) is the minterm of the select lines. A 2:1 MUX is Y=S′I0+SI1Y = S'I_0 + SI_1; a 4:1 MUX is

Y=S1′S0′I0+S1′S0I1+S1S0′I2+S1S0I3.Y = S_1'S_0'I_0 + S_1'S_0I_1 + S_1S_0'I_2 + S_1S_0I_3 .

At gate level, a 2n ⁣: ⁣12^n\!:\!1 MUX is 2n2^n AND gates of n+1n+1 inputs feeding one 2n2^n-input OR, plus nn inverters for the selects.

Select order matters. S1S_1 is the more significant select. Swapping the wires on S1S_1 and S0S_0 permutes I1I_1 and I2I_2.

Implementing functions with a MUX

Shannon-expand ff on the variables used as selects:

f=∑kmk(selects)⋅fk,f = \sum_{k} m_k(\text{selects})\cdot f_k ,

where fkf_k is the cofactor (residual function) when the selects equal kk. Tie each data input to its cofactor.

  • nn variables on a 2n ⁣: ⁣12^n\!:\!1 MUX: every cofactor is a constant, so Ik=f(k)I_k = f(k), the truth-table column.
  • nn variables on a 2n−1 ⁣: ⁣12^{n-1}\!:\!1 MUX: put n−1n-1 variables on the selects; each cofactor is a function of the last variable xx, so it is one of 00, 11, xx, x′x'. Any nn-variable function fits, given the complement of xx.
  • Fewer selects: the cofactors become functions of two or more variables and need extra gates.

Universality. A 2:1 MUX with constants 0 and 1 available is functionally complete: x′=MUX(S=x;I0=1,I1=0)x' = \mathrm{MUX}(S = x; I_0 = 1, I_1 = 0), xy=MUX(S=x;I0=0,I1=y)xy = \mathrm{MUX}(S = x; I_0 = 0, I_1 = y) and x+y=MUX(S=x;I0=y,I1=1)x + y = \mathrm{MUX}(S = x; I_0 = y, I_1 = 1).

Decoder

An n ⁣→ ⁣2nn\!\to\!2^n line decoder asserts output OiO_i iff the input equals ii (and enable is on). Outputs are exactly the minterms of the inputs, so it uses 2n2^n AND gates of nn inputs (n+1n + 1 with an enable). Any function of the same inputs is the OR of the outputs in its on-set, and one decoder serves several functions at once.

Active-low outputs. Many decoders (for example the 74x138 style) have active-low outputs Oi‾=Mi\overline{O_i} = M_i, the maxterms. Then f=∑m(…)f = \sum m(\ldots) is a NAND of the selected lines, and an AND of the lines for the off-set gives ff as a product of maxterms.

Decoder trees. Larger decoders come from enables. Two 2-to-4 decoders with enables a2′a_2' and a2a_2 give a 3-to-8 decoder (Figure 2). A 4-to-16 decoder takes five 2-to-4 decoders: one decodes a3a2a_3a_2 and its four outputs enable four decoders of a1a0a_1a_0.

Encoder

A 2n ⁣→ ⁣n2^n\!\to\!n encoder assumes exactly one input is 1 and outputs its index. For 8-to-3:

Y2=D4+D5+D6+D7,Y1=D2+D3+D6+D7,Y0=D1+D3+D5+D7.Y_2 = D_4+D_5+D_6+D_7,\quad Y_1 = D_2+D_3+D_6+D_7,\quad Y_0 = D_1+D_3+D_5+D_7 .

Each output ORs the inputs whose index has that bit set. With two inputs active the output is the bitwise OR of the two indices (D3D_3 and D5D_5 give 111111, which is neither), and "no input" gives 000000, the same as D0D_0.

A priority encoder accepts several 1s and outputs the index of the highest-priority 1, plus a valid flag VV that distinguishes "D0D_0 only" from "nothing active".

Demultiplexer

Routes one data input DD to the selected output line: Oi=D⋅mi(S)O_i = D\cdot m_i(S). A decoder with enable is a demultiplexer: drive the enable with DD and the inputs with the selects.

4:1 MUX implementing a Boolean function of two variables
Figure 1. A 4:1 MUX with selects a,ba,b and data I0..I3=0,1,1,0I_0..I_3=0,1,1,0 realizing a⊕ba\oplus b.
Decoder expansion tree from 2-to-4 blocks to 3-to-8
Figure 2. Two 2-to-4 decoders with enables driven by a high-order bit, forming a 3-to-8 decoder.

How it works

MUX from gates

Each data path is AND with its select minterm; OR all paths. Transmission-gate MUXes appear in VLSI; GATE sticks to the logic model.

MUX trees

A 2n ⁣: ⁣12^n\!:\!1 MUX from 2:1 MUXes is a binary tree: 2n−12^{n-1} at the first level (selected by S0S_0), then 2n−22^{n-2} (by S1S_1), and so on, for 2n−12^n - 1 MUXes and nn levels. From 4:1 MUXes, a 16:1 MUX takes four on the first level (selected by S1S0S_1S_0) and one on the second (by S3S2S_3S_2): five in all. The lower select bits go to the first level; feeding them to the wrong level permutes the data inputs.

TargetFrom 2:1From 4:1Levels with 4:1
4:1311
8:172 + one 2:12
16:11552
64:163213

Evaluating a MUX cascade

Simulate one MUX at a time: write each output as S′I0+SI1S'I_0 + SI_1 with the actual signals, or build the truth table row by row. A MUX whose select is driven by another MUX output still obeys Y=ISY = I_S for each row.

Algorithms and pseudocode

Arrays are 0-indexed; <- is assignment.

Text
MUX-EVAL(I[0..2^n-1], S)
1  return I[integer(S)]

DECODER(n, x, en)
1  for i <- 0 to 2^n - 1
2      O[i] <- en AND (x = i)
3  return O

MUX-DATA-INPUTS(f, n)          // f on n variables, selects = first n-1
1  for k <- 0 to 2^(n-1) - 1
2      f0 <- f(row 2k)          // last variable x = 0
3      f1 <- f(row 2k + 1)      // x = 1
4      if f0 = f1 then I[k] <- f0          // constant 0 or 1
5      else if f1 = 1 then I[k] <- x
6      else I[k] <- NOT x
7  return I

PRIORITY-ENCODE(D[0..m-1])     // highest index wins
1  for i <- m-1 downto 0
2      if D[i] = 1 then return (i, valid = 1)
3  return (0, valid = 0)

MUX-DATA-INPUTS reads the truth table once, Θ(2n)\Theta(2^n) work. Rows 2k2k and 2k+12k + 1 differ only in the last variable because that variable is the least significant bit of the row index.

Software cost model. Use unpacked word arrays, unit-cost indexed lookup/write, and words wide enough for the loop bounds and packed indices. Assume SS and xx already hold packed indices: MUX-EVAL takes Θ(1)\Theta(1) time and O(1)O(1) workspace in every case, excluding its input array and scalar output. Reading SS from an unpacked nn-bit array instead adds Θ(n+1)\Theta(n+1) conversion work. DECODER writes all 2n2^n entries even when disabled: Θ(2n)\Theta(2^n) time and output words in best, average and worst cases, with O(1)O(1) workspace beyond input/output. For n≥1n\ge1, constant-time truth-table access makes MUX-DATA-INPUTS read exactly 2n2^n rows and write 2n−12^{n-1} fixed-size descriptors (0, 1, xx, or NOT xx); time is Θ(2n)\Theta(2^n) in every case and working space O(1)O(1) beyond input/output. For m≥1m\ge1, PRIORITY-ENCODE has Θ(1)\Theta(1) best time and Θ(m)\Theta(m) worst time, with O(1)O(1) workspace excluding its input and two-word result. Average time needs a distribution: with exactly one 1 uniformly located it examines (m+1)/2(m+1)/2 entries on average, hence Θ(m)\Theta(m). These sequential software costs are not circuit gate counts or propagation delays.

Mathematical explanation

A decoder computes the standard basis of indicator functions on {0,1}n\{0,1\}^n. Any function is the OR (sum) of those indicators where the table is 1: decoder plus OR. A MUX with selects on all variables and data in {0,1}\{0,1\} is a ROM-like realization of one output column.

Shannon expansion. For any variable xx,

f=x′f∣x=0+xf∣x=1,f = x' f|_{x=0} + x f|_{x=1},

which is exactly a 2:1 MUX with select xx. Applying it to kk variables at once gives the 2k ⁣: ⁣12^k\!:\!1 MUX form. A function with nn variables has 22n2^{2^n} possibilities; a 2n−1 ⁣: ⁣12^{n-1}\!:\!1 MUX with data from {0,1,x,x′}\{0, 1, x, x'\} has 42n−1=22n4^{2^{n-1}} = 2^{2^n} settings, one per function, which is another way to see that every function fits.

Priority-encoder equations (4 to 2, D3D_3 highest). Y1=1Y_1 = 1 when the winner is D3D_3 or D2D_2: Y1=D3+D2Y_1 = D_3 + D_2. Y0=1Y_0 = 1 when the winner is D3D_3, or D1D_1 with D2D_2 and D3D_3 off: Y0=D3+D3′D2′D1Y_0 = D_3 + D_3'D_2'D_1, which simplifies to Y0=D3+D2′D1Y_0 = D_3 + D_2'D_1. And V=D3+D2+D1+D0V = D_3 + D_2 + D_1 + D_0.

D3D_3D2D_2D1D_1D0D_0Y1Y_1Y0Y_0VV
0000XX0
0001001
001X011
01XX101
1XXX111

Worked examples

Example 1: XOR on 4:1 MUX

Selects a,ba,b; I=(0,1,1,0)I=(0,1,1,0). Output equals a⊕ba\oplus b, the truth-table column of XOR.

Example 2: f=∑m(1,2,4,7)f=\sum m(1,2,4,7) with 3-to-8 decoder

OR outputs O1,O2,O4,O7O_1,O_2,O_4,O_7. This ff is a⊕b⊕ca \oplus b \oplus c, the full-adder sum; the same decoder gives the carry ∑m(3,5,6,7)\sum m(3,5,6,7) with a second OR. A full adder is one 3-to-8 decoder plus two 4-input OR gates. With active-low outputs, use two 4-input NAND gates.

Example 3: priority encoder 4 to 2

Inputs w3..w0w_3..w_0 with w3w_3 highest priority. If w3=1w_3=1, out 1111; else if w2=1w_2=1, out 1010; else if w1=1w_1=1, out 0101; else if w0=1w_0=1, out 0000; valid =w3+w2+w1+w0= w_3+w_2+w_1+w_0. For input 01100110 (w2=w1=1w_2 = w_1 = 1) the output is 1010 with V=1V = 1; a plain encoder would give 10+01=1110 + 01 = 11.

Example 4: expand 2-to-4 to 3-to-8

High bit a2a_2 enables one of two 2-to-4 blocks that receive a1a0a_1 a_0: a2=0a_2 = 0 enables the block for O0..O3O_0..O_3, a2=1a_2 = 1 the block for O4..O7O_4..O_7. For input 110110, only the lower (O4-O7) block is enabled and its line 1010 fires: O6O_6.

Example 5: three variables on a 4:1 MUX

f=∑m(1,4,5,7)f=\sum m(1,4,5,7) for abcabc, selects a,ba,b. Residuals: ab=00ab=00 (rows 0,1) →c\to c; ab=01ab=01 (rows 2,3) →0\to 0; ab=10ab=10 (rows 4,5) →1\to 1; ab=11ab=11 (rows 6,7) →c\to c. Data ties I=(c,0,1,c)I=(c,0,1,c).

Example 6: four variables on an 8:1 MUX

f(A,B,C,D)=∑m(0,1,3,4,8,9,15)f(A,B,C,D)=\sum m(0,1,3,4,8,9,15) with selects A,B,CA,B,C and data in terms of DD. Pair rows 2k,2k+12k, 2k+1:

ABCABCRowsff at D=0,1D = 0, 1IkI_k
0000, 11, 11
0012, 30, 1DD
0104, 51, 0D′D'
0116, 70, 00
1008, 91, 11
10110, 110, 00
11012, 130, 00
11114, 150, 1DD

So I=(1,D,D′,0,1,0,0,D)I = (1, D, D', 0, 1, 0, 0, D).

Example 7: a MUX cascade

m1=MUX(S=a;I0=b,I1=b′)m_1 = \mathrm{MUX}(S = a; I_0 = b, I_1 = b') and f=MUX(S=c;I0=m1,I1=a′)f = \mathrm{MUX}(S = c; I_0 = m_1, I_1 = a'). Then m1=a′b+ab′=a⊕bm_1 = a'b + ab' = a \oplus b and f=c′(a⊕b)+c a′f = c'(a \oplus b) + c\,a'. Rows abcabc with c=0c = 0 give the on-set where a≠ba \ne b: 2 (010) and 4 (100). Rows with c=1c = 1 give the on-set where a=0a = 0: 1 (001) and 3 (011). So f=∑m(1,2,3,4)f = \sum m(1,2,3,4).

Example 8: how many 2:1 MUXes for XOR?

With only aa, bb, 0 and 1 available (no inverters), a single 2:1 MUX reaches exactly 12 of the 16 two-variable functions: 00, 11, aa, bb, a′a', b′b', abab, ab′ab', a′ba'b, a+ba+b, a+b′a+b' and a′+ba'+b. The four it misses are XOR, XNOR, NAND and NOR. Two suffice: t=MUX(S=b;1,0)=b′t = \mathrm{MUX}(S = b; 1, 0) = b', then a⊕b=MUX(S=a;b,t)a \oplus b = \mathrm{MUX}(S = a; b, t).

Important properties and observations

  • Active-low outputs (bubbles) on decoders are common; OR becomes NAND of active-low lines (De Morgan).
  • MUX tree: 2n−12^n - 1 two-input MUXes for 2n ⁣: ⁣12^n\!:\!1; with 4:1 blocks, 16:1 takes 5.
  • Decoder tree: a 4-to-16 decoder takes five 2-to-4 decoders, or two 3-to-8 decoders whose enables are a3′a_3' and a3a_3.
  • Encoder without priority is undefined for non-one-hot inputs; if the stem does not say, check whether the options assume a priority encoder.
  • A decoder plus OR gates realizes any number of functions of the same inputs; a MUX realizes one function per MUX.

Common misconceptions.

  • "Decoder has nn outputs." It has 2n2^n outputs.
  • "MUX data inputs must be constants." They may be variables when residual Shannon cofactors need them.
  • "Any wiring of the selects works." The select that is the MSB picks between the upper and lower halves of the data inputs; swapping selects permutes I1I_1 and I2I_2 on a 4:1 MUX.
  • "An encoder output of 000 means input D0D_0." It also means no input; only VV tells them apart.

GATE examination perspective

  • MUX REALIZATION. Draw selects and list I0..IkI_0..I_k values (0/1/x/x′0/1/x/x'); remember the last variable is the LSB of the row index.
  • CASCADES. Evaluate MUX by MUX and build the truth table.
  • DECODER PLUS OR. Count which output lines feed the OR; active-low outputs need NAND.
  • TREE COUNTS. 2n−12^n - 1 two-input MUXes; five 2-to-4 decoders for 4-to-16.
  • ENABLE LOGIC. Disabled decoder drives all zeros (active high).
  • PRIORITY ORDER. State which input wins and use VV.

Summary

Sources

  1. M. Morris Mano, M. D. Ciletti, Digital Design, 5th ed., Pearson, 2013: Chapter 4, Sections 4.9 to 4.11 (decoders, encoders, multiplexers).

Next steps