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 outputs from an -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 MUX has data inputs , select lines , and one output , where the select lines are read as a binary number. Enable (active low or high) may force when disabled.
Boolean form. where is the minterm of the select lines. A 2:1 MUX is ; a 4:1 MUX is
At gate level, a MUX is AND gates of inputs feeding one -input OR, plus inverters for the selects.
Select order matters. is the more significant select. Swapping the wires on and permutes and .
Implementing functions with a MUX
Shannon-expand on the variables used as selects:
where is the cofactor (residual function) when the selects equal . Tie each data input to its cofactor.
- variables on a MUX: every cofactor is a constant, so , the truth-table column.
- variables on a MUX: put variables on the selects; each cofactor is a function of the last variable , so it is one of , , , . Any -variable function fits, given the complement of .
- 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: , and .
Decoder
An line decoder asserts output iff the input equals (and enable is on). Outputs are exactly the minterms of the inputs, so it uses AND gates of inputs ( 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 , the maxterms. Then is a NAND of the selected lines, and an AND of the lines for the off-set gives as a product of maxterms.
Decoder trees. Larger decoders come from enables. Two 2-to-4 decoders with enables and give a 3-to-8 decoder (Figure 2). A 4-to-16 decoder takes five 2-to-4 decoders: one decodes and its four outputs enable four decoders of .
Encoder
A encoder assumes exactly one input is 1 and outputs its index. For 8-to-3:
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 ( and give , which is neither), and "no input" gives , the same as .
A priority encoder accepts several 1s and outputs the index of the highest-priority 1, plus a valid flag that distinguishes " only" from "nothing active".
Demultiplexer
Routes one data input to the selected output line: . A decoder with enable is a demultiplexer: drive the enable with and the inputs with the selects.


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 MUX from 2:1 MUXes is a binary tree: at the first level (selected by ), then (by ), and so on, for MUXes and levels. From 4:1 MUXes, a 16:1 MUX takes four on the first level (selected by ) and one on the second (by ): five in all. The lower select bits go to the first level; feeding them to the wrong level permutes the data inputs.
| Target | From 2:1 | From 4:1 | Levels with 4:1 |
|---|---|---|---|
| 4:1 | 3 | 1 | 1 |
| 8:1 | 7 | 2 + one 2:1 | 2 |
| 16:1 | 15 | 5 | 2 |
| 64:1 | 63 | 21 | 3 |
Evaluating a MUX cascade
Simulate one MUX at a time: write each output as with the actual signals, or build the truth table row by row. A MUX whose select is driven by another MUX output still obeys for each row.
Algorithms and pseudocode
Arrays are 0-indexed; <- is assignment.
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, work. Rows and 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 and already hold packed indices: MUX-EVAL takes time and workspace in every case, excluding its input array and scalar output. Reading from an unpacked -bit array instead adds conversion work. DECODER writes all entries even when disabled: time and output words in best, average and worst cases, with workspace beyond input/output. For , constant-time truth-table access makes MUX-DATA-INPUTS read exactly rows and write fixed-size descriptors (0, 1, , or NOT ); time is in every case and working space beyond input/output. For , PRIORITY-ENCODE has best time and worst time, with workspace excluding its input and two-word result. Average time needs a distribution: with exactly one 1 uniformly located it examines entries on average, hence . These sequential software costs are not circuit gate counts or propagation delays.
Mathematical explanation
A decoder computes the standard basis of indicator functions on . 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 is a ROM-like realization of one output column.
Shannon expansion. For any variable ,
which is exactly a 2:1 MUX with select . Applying it to variables at once gives the MUX form. A function with variables has possibilities; a MUX with data from has settings, one per function, which is another way to see that every function fits.
Priority-encoder equations (4 to 2, highest). when the winner is or : . when the winner is , or with and off: , which simplifies to . And .
| 0 | 0 | 0 | 0 | X | X | 0 |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | X | 0 | 1 | 1 |
| 0 | 1 | X | X | 1 | 0 | 1 |
| 1 | X | X | X | 1 | 1 | 1 |
Worked examples
Example 1: XOR on 4:1 MUX
Selects ; . Output equals , the truth-table column of XOR.
Example 2: with 3-to-8 decoder
OR outputs . This is , the full-adder sum; the same decoder gives the carry 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 with highest priority. If , out ; else if , out ; else if , out ; else if , out ; valid . For input () the output is with ; a plain encoder would give .
Example 4: expand 2-to-4 to 3-to-8
High bit enables one of two 2-to-4 blocks that receive : enables the block for , the block for . For input , only the lower (O4-O7) block is enabled and its line fires: .
Example 5: three variables on a 4:1 MUX
for , selects . Residuals: (rows 0,1) ; (rows 2,3) ; (rows 4,5) ; (rows 6,7) . Data ties .
Example 6: four variables on an 8:1 MUX
with selects and data in terms of . Pair rows :
| Rows | at | ||
|---|---|---|---|
| 000 | 0, 1 | 1, 1 | 1 |
| 001 | 2, 3 | 0, 1 | |
| 010 | 4, 5 | 1, 0 | |
| 011 | 6, 7 | 0, 0 | 0 |
| 100 | 8, 9 | 1, 1 | 1 |
| 101 | 10, 11 | 0, 0 | 0 |
| 110 | 12, 13 | 0, 0 | 0 |
| 111 | 14, 15 | 0, 1 |
So .
Example 7: a MUX cascade
and . Then and . Rows with give the on-set where : 2 (010) and 4 (100). Rows with give the on-set where : 1 (001) and 3 (011). So .
Example 8: how many 2:1 MUXes for XOR?
With only , , 0 and 1 available (no inverters), a single 2:1 MUX reaches exactly 12 of the 16 two-variable functions: , , , , , , , , , , and . The four it misses are XOR, XNOR, NAND and NOR. Two suffice: , then .
Important properties and observations
- Active-low outputs (bubbles) on decoders are common; OR becomes NAND of active-low lines (De Morgan).
- MUX tree: two-input MUXes for ; 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 and .
- 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 outputs." It has 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 and on a 4:1 MUX.
- "An encoder output of 000 means input ." It also means no input; only tells them apart.
GATE examination perspective
- MUX REALIZATION. Draw selects and list values (); 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. 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 .
Summary
Sources
- M. Morris Mano, M. D. Ciletti, Digital Design, 5th ed., Pearson, 2013: Chapter 4, Sections 4.9 to 4.11 (decoders, encoders, multiplexers).