In Multiplexers we built a circuit that takes many inputs and lets exactly one of them through to a single output. Very often we need the opposite job: one stream of data has to be sent to one of many destinations. A single cable arrives at a building, and the data on it must reach the correct floor. The processor writes a value, and it must land in the correct register. That "distributor" circuit is the demultiplexer.
A demultiplexer (DEMUX, data distributor) has one data input D, n select lines and 2n outputs. The select lines choose which output receives D; every other output stays at 0.
Think of a railway junction seen from the other side: one track comes in, and the points (select lines) decide which of several tracks the train goes down. Or think of the person sorting letters at a post office: one pile comes in, each letter goes into exactly one pigeon-hole according to its PIN code.
In this chapter we design the 1-to-2, 1-to-4 and 1-to-8 demultiplexers, see why a demultiplexer and a decoder are really the same circuit, build large demultiplexers from small ones, implement Boolean functions with them and write one in Verilog.
1-to-2 Demultiplexer
The smallest demultiplexer has one select line S and two outputs Y0 and Y1. When S = 0 the data goes to Y0; when S = 1 it goes to Y1.
S | Y1 | Y0 |
|---|---|---|
0 | 0 | D |
1 | D | 0 |
Y0 = S′·D
Y1 = S·D
Notice how the truth table is written: instead of listing D = 0 and D = 1 separately, we write "D" in the output column. This compressed table is standard for multiplexers and demultiplexers. The circuit is one NOT gate and two 2-input AND gates. Each AND gate is a "gate" in the everyday sense of the word: it opens (passes D) only when its select condition is true.
1-to-4 Demultiplexer
With two select lines S1 S0 we can address four outputs.
S1 | S0 | Y3 | Y2 | Y1 | Y0 |
|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | D |
0 | 1 | 0 | 0 | D | 0 |
1 | 0 | 0 | D | 0 | 0 |
1 | 1 | D | 0 | 0 | 0 |
Y0 = S1′·S0′·D
Y1 = S1′·S0 ·D
Y2 = S1 ·S0′·D
Y3 = S1 ·S0 ·D
Each output is "one minterm of the select lines, ANDed with D". The circuit:
S1 ──>[NOT]──> S1′ S0 ──>[NOT]──> S0′
select terms data
AND0 : S1′ , S0′ , D ──> Y0
AND1 : S1′ , S0 , D ──> Y1
AND2 : S1 , S0′ , D ──> Y2
AND3 : S1 , S0 , D ──> Y3
D is wired to all four AND gates; the select terms open exactly one of them.
Hardware: 2 NOT gates + 4 three-input AND gates
Generalising to 1-to-2n
In a 1-to-2n demultiplexer, output Yi = mi·D, where mi is the i-th minterm of the n select variables.
A 1-to-8 demultiplexer therefore needs 3 NOT gates and 8 four-input AND gates (3 select literals + D). For example Y5 = S2S1′S0·D, because 5 = 101.
Example 1: Tracing a 1-to-8 Demultiplexer
D is a square wave and S2S1S0 = 110. Which output carries the wave?
110 in binary is 6, so only m6 = S2S1S0′ is 1.
Y6 = 1·D = D: the square wave appears on Y6.
All of Y0 to Y5 and Y7 are held at 0 regardless of D.
If D is held at 0, all eight outputs are 0, even the selected one. That is the defining behaviour: the selected output simply copies D.
Demultiplexer = Decoder with Enable
Compare the 1-to-4 demultiplexer with a 2-to-4 decoder that has an enable input E (covered fully in Decoders & Encoders). The decoder's outputs are Di = mi·E. Rename E as D and you get exactly the demultiplexer equations.
View | Inputs called | Outputs | Typical use |
|---|---|---|---|
2-to-4 decoder with enable | A1A0 = address, E = enable | The addressed line goes to 1 (if E = 1) | Selecting one chip or register |
1-to-4 demultiplexer | S1S0 = select, D = data | The selected line copies D | Routing a data stream |
The hardware is identical; only our interpretation of the inputs changes. That is why IC catalogues sell parts named "decoder/demultiplexer". The classic 74HC138 (74LS138) is a 3-to-8 decoder with three enables, G1 (active-high), G2A′ and G2B′ (both active-low), and active-low outputs. To use it as a 1-to-8 demultiplexer, put the data on G2A′, tie G1 high and G2B′ low. When D = 0 the chip is enabled and the selected output goes LOW; when D = 1 the chip is disabled and all outputs are HIGH. So the selected output copies D exactly, while the unselected outputs sit at HIGH (their inactive level, since the outputs are active-low). Similarly the 74155 is a dual 2-to-4 decoder/demultiplexer.
Building Larger Demultiplexers
Suppose you only have 1-to-4 demultiplexers and you need a 1-to-16 one. Build a tree:
S1 S0 (to all four)
┌──> [1-to-4] ──> Y0 Y1 Y2 Y3
S3 S2 ├──> [1-to-4] ──> Y4 Y5 Y6 Y7
D ──────> [1-to-4] ────────┼──> [1-to-4] ──> Y8 Y9 Y10 Y11
(level 1) └──> [1-to-4] ──> Y12 Y13 Y14 Y15
(level 2)
Total = 1 + 4 = 5 demultiplexers
Pay attention to which select bits go where. The first level (the one that receives D) uses the most significant select bits S3S2: they decide which group of four outputs gets the data. The second level uses S1S0 to pick the output within the group. Then the output number is 4·(S3S2) + (S1S0), which is exactly the binary number S3S2S1S0. (It is the mirror image of a multiplexer tree, where the last level, nearest the output, uses the most significant selects.)
Building a 1-to-N demultiplexer from 1-to-k demultiplexers (N a power of k) takes N/k + N/k2 + ... + 1 = (N − 1)/(k − 1) devices. From 1-to-2 demultiplexers this is N − 1.
Target | Built from | Count |
|---|---|---|
1-to-8 | 1-to-2 | 4 + 2 + 1 = 7 |
1-to-16 | 1-to-4 | 4 + 1 = 5 |
1-to-32 | 1-to-2 | 16 + 8 + 4 + 2 + 1 = 31 |
1-to-64 | 1-to-8 | 8 + 1 = 9 |
1-to-64 | 1-to-4 | 16 + 4 + 1 = 21 |
If N is not a power of k, count level by level from the outputs. Example: 1-to-32 from 1-to-4 needs 8 devices to produce 32 outputs (selects S1S0), 2 devices to feed those 8 (selects S3S2), and one more device at the top to feed those 2 (select S4, using only two of its outputs): 8 + 2 + 1 = 11.
MUX + DEMUX: Sharing One Wire
The most famous use of a demultiplexer is together with a multiplexer for time-division multiplexing (TDM). Four sensors must send data to four displays, but only one wire runs between the two buildings.
Sensor0 ─┐ ┌──> Display0
Sensor1 ─┤ 4-to-1 1-to-4 ├──> Display1
Sensor2 ─┤ MUX ─── one wire ─── DEMUX ├──> Display2
Sensor3 ─┘ └──> Display3
↑ ↑
S1 S0 ── same counter ── S1 S0 (00, 01, 10, 11, 00, ...)
A 2-bit counter drives the select lines of both ends with the same value at the same time. In time slot 00 sensor 0 is connected through to display 0, in slot 01 sensor 1 to display 1, and so on. If the select lines at the two ends ever get out of step, sensor 1's data shows up on display 2: synchronisation is the whole game. Telephone exchanges and many serial buses work on this principle.
Implementing Functions with a Demultiplexer
Tie D = 1. Now each output is a pure minterm of the select variables, Yi = mi. Any function written as a sum of minterms is then just an OR of the right outputs, exactly like using a decoder.
Example 2: Full Subtractor with a 1-to-8 Demultiplexer
A full subtractor computes A − B − Bin (see Subtractors). Connect S2 = A, S1 = B, S0 = Bin and D = 1.
A B Bin | Minterm | Difference | Borrow out |
|---|---|---|---|
000 | m0 | 0 | 0 |
001 | m1 | 1 | 1 |
010 | m2 | 1 | 1 |
011 | m3 | 0 | 1 |
100 | m4 | 1 | 0 |
101 | m5 | 0 | 0 |
110 | m6 | 0 | 0 |
111 | m7 | 1 | 1 |
Difference = Σm(1, 2, 4, 7) → Diff = Y1 + Y2 + Y4 + Y7 (one 4-input OR)
Borrow = Σm(1, 2, 3, 7) → Bout = Y1 + Y2 + Y3 + Y7 (one 4-input OR)
Hardware: one 1-to-8 DEMUX (D = 1) + two 4-input OR gates
Check one row: A = 0, B = 1, Bin = 1 means 0 − 1 − 1 = −2, which is difference 0 with a borrow of 1 (since −2 = 0 − 2·1). Only Y3 is 1; Y3 is in the Borrow OR but not in the Difference OR, so Diff = 0, Bout = 1. Correct.
Active-Low Outputs
Real chips like the 74138 have active-low outputs: the selected output is 0, the rest are 1. Then each output is mi′, and an OR of minterms becomes a NAND of the active-low outputs (by De Morgan, m1 + m2 = (m1′·m2′)′). So with active-low outputs, use NAND gates instead of OR gates.
Verilog Model
Here is a 1-to-4 demultiplexer written directly from the equations, with a testbench that tries all eight combinations of D, S1, S0.
// 1-to-4 demultiplexer, gate-level equations
module demux1to4 (input logic d, input logic [1:0] s, output logic [3:0] y);
assign y[0] = ~s[1] & ~s[0] & d;
assign y[1] = ~s[1] & s[0] & d;
assign y[2] = s[1] & ~s[0] & d;
assign y[3] = s[1] & s[0] & d;
endmodule
module tb;
logic d; logic [1:0] s; logic [3:0] y;
demux1to4 dut (.d(d), .s(s), .y(y));
initial begin
$display("D S1S0 | Y3 Y2 Y1 Y0");
for (int i = 0; i < 8; i++) begin
{d, s} = i[2:0];
#1 $display("%b %b | %b %b %b %b", d, s, y[3], y[2], y[1], y[0]);
end
end
endmodule
Output (iverilog -g2012, vvp):
D S1S0 | Y3 Y2 Y1 Y0
0 00 | 0 0 0 0
0 01 | 0 0 0 0
0 10 | 0 0 0 0
0 11 | 0 0 0 0
1 00 | 0 0 0 1
1 01 | 0 0 1 0
1 10 | 0 1 0 0
1 11 | 1 0 0 0
The first four lines confirm that with D = 0 nothing is sent anywhere; the last four show the single 1 walking from Y0 to Y3 as the select value counts up.
MUX vs DEMUX
Point | Multiplexer | Demultiplexer |
|---|---|---|
Data inputs → outputs | 2n → 1 | 1 → 2n |
Select lines | n | n |
Other name | Data selector | Data distributor |
Equation | Y = Σ mi·Ii | Yi = mi·D |
Gates (n selects) | 2n ANDs + one 2n-input OR | 2n ANDs, no OR |
Function implementation | Alone (truth table on data inputs) | Needs an extra OR (or NAND) gate per output |
Data conversion | Parallel → serial | Serial → parallel |
Equivalent block | - | Decoder with enable |
Where Demultiplexers Are Used
Serial-to-parallel conversion: bits arriving one after another on a line are steered to successive outputs.
Write path of a register file or memory: the write-enable pulse is routed only to the register or chip that is being written.
TDM receivers: the receiving end of a shared communication line.
Driving multiplexed displays: steering a drive signal to one digit of a multi-digit display at a time.
Clock or control distribution: sending a control pulse to one of several units.
Common Mistakes
Thinking the selected output is always 1. It equals D. If D = 0 every output is 0.
Saying the unselected outputs "float" or keep old values. A demultiplexer is combinational: unselected outputs are driven to 0 (or to 1 on chips with active-low outputs). It remembers nothing.
Wiring a demultiplexer tree with the LSB selects at the first level. Then the outputs come out in a scrambled order. The level that receives D uses the most significant select bits.
Counting a tree as N/k devices. You must add the upper levels: 1-to-16 from 1-to-4 needs 5, not 4.
Using OR gates on active-low outputs. With active-low outputs, combine minterms with a NAND gate.
Mixing up "1-to-4 demux" with "4-to-1 mux". The demultiplexer has one data input; the multiplexer has one output.
Interview and GATE Questions
Q1. How many 1-to-2 demultiplexers are needed to build a 1-to-32 demultiplexer?
N − 1 = 31 (levels of 1 + 2 + 4 + 8 + 16).
Q2. In a 1-to-8 demultiplexer, S2S1S0 = 011 and D = 0. What are the outputs?
All eight outputs are 0. Y3 is selected, but it copies D, which is 0.
Q3. Implement F(A, B, C) = Σm(0, 3, 5, 6) using a 1-to-8 demultiplexer.
Connect A, B, C to S2, S1, S0, tie D = 1 and take F = Y0 + Y3 + Y5 + Y6. (This F is 1 when an even number of inputs are 1, i.e. F = (A ⊕ B ⊕ C)′.) With active-low outputs, use a 4-input NAND of those four outputs instead.
Q4. Why is a demultiplexer called a decoder with enable?
A decoder with enable has outputs mi·E and a demultiplexer has outputs mi·D. The circuits are identical; the enable input is simply used as the data input.
Q5. In a 1-to-16 demultiplexer built from five 1-to-4 demultiplexers, which select bits drive the first-level device?
The two most significant bits, S3S2. They choose one of the four second-level devices (one group of four outputs); S1S0, wired to all four second-level devices, pick the output within the group.
Q6. A 4-to-1 MUX and a 1-to-4 DEMUX share one wire. What condition must hold for correct transmission?
Both ends must have the same select value at the same time (synchronised select lines, usually driven by the same counter or by a clock and frame-sync signal). Otherwise data reaches the wrong output.
Q7. How many AND gates (and of what size) does a 1-to-16 demultiplexer need if built directly?
16 AND gates with 5 inputs each (4 select literals + D), plus 4 NOT gates for the complemented selects.
Summary
A demultiplexer sends one data input D to one of 2n outputs chosen by n select lines: Yi = mi·D.
Unselected outputs are 0; the selected output equals D (not necessarily 1).
A demultiplexer is the same circuit as a decoder with enable; chips like the 74138 serve as both.
Large demultiplexers are built as trees, with the most significant selects at the first level; 1-to-N from 1-to-k needs (N − 1)/(k − 1) devices.
With D = 1 a demultiplexer generates all minterms, so any function is an OR (or a NAND, for active-low outputs) of selected outputs.
MUX at the sender plus DEMUX at the receiver with synchronised selects gives time-division multiplexing over one wire.
Next, Decoders & Encoders looks at the decoder view in depth, plus its inverse, the encoder.