The idea: blocks with named pins
Once you know gates, you stop drawing them one by one. Designers reuse a few ready-made building blocks: the multiplexer, the demultiplexer, the decoder and the encoder. In the 7400 chip family each one was a single chip with about 10 to 100 gates, which is called medium-scale integration (MSI). Inside a processor or an FPGA the same blocks are everywhere.
This page treats each block as a box with named pins. Pick a tab, change an input, and watch the value go from its input pin to its output pin. A wire at 1 is dark blue, a wire at 0 is grey, and the path the select bits connect is orange. The truth table on the right lights the row for the current input. To see the gates inside a 2:1 mux and a 2:4 decoder, with their delays and glitches, see Combinational Logic.
The multiplexer: a switch set by a number
A 2n:1 multiplexer (mux) has 2n data inputs I0, I1, …, n select lines and one output Y. Read the select bits as a binary number k. The mux connects input Ik to Y and ignores all the others: Y = IS. So a 4:1 mux needs 2 select lines and an 8:1 mux needs 3.
On the page the data inputs are fixed at I0…I7 = 0 1 1 0 0 1 0 1. Demo: S = 5, then 3 sets S2 S1 S0 = 101, so I5 = 1 reaches Y. Then S = 011 picks I3 = 0, and Y drops to 0. Switch the size to 4:1 and only I0…I3 and S1 S0 are left.
Written as a sum of products, a 4:1 mux is Y = S1'S0'·I0 + S1'S0·I1 + S1S0'·I2 + S1S0·I3. Each AND term is a decoder output ANDed with one data input. A wide mux can also be a tree of smaller ones: two 4:1 muxes on S1 S0, then a 2:1 mux on S2, make an 8:1 mux.
The demultiplexer and the decoder
A 1:2n demultiplexer does the opposite of a mux. It has one data input D and the select bits pick which output gets it. Every other output is 0. Demo: D to Y2 sets S1 S0 = 10: Y3 Y2 Y1 Y0 = 0100. With D = 0 all four outputs are 0, whichever one is selected.
An n:2n decoder turns an n-bit number A into 2n lines and raises exactly one of them, YA. Each output is one minterm of the address: Y5 = E·A2·A1'·A0. The enable input E is ANDed into every term, so E = 0 turns every output off. Demo: A = 5, then E = 0 shows both.
Look at the two tables side by side: a decoder with enable is a demultiplexer whose data input is called E. That is why chip catalogues sell the 74HC138 as a "3-to-8 line decoder/demultiplexer". Decoders pick the register to write, the memory chip to enable (see Memory Arrays, where a decoder drives the wordlines) and the device a CPU address belongs to.
The encoder and the priority encoder
An encoder goes back from lines to a number: 8 inputs D0…D7 in, the 3-bit index of the input that is 1 out. A plain 8:3 encoder is just three OR gates:
Y2 = D4 + D5 + D6 + D7 Y1 = D2 + D3 + D6 + D7 Y0 = D1 + D3 + D5 + D7
That works only if exactly one input is 1 (a one-hot input). It has two problems:
- With two inputs high it gives a wrong number. D4 and D2 give 100 OR 010 = 110, which says "D6".
- With no input high it gives 000, the same as D0 alone.
A priority encoder fixes both. It outputs the index of the highest input that is 1 and ignores the ones below. It also has a valid output V = D0 + D1 + … + D7, which is 0 when no input is high. Demo: plain vs priority feeds D4 and D2 to both: the plain encoder says 110 = 6, the priority encoder 100 = 4 with V = 1. Demo: valid bit shows D0 alone (000, V = 1) and then nothing (000, V = 0). Interrupt controllers use a priority encoder to pick which pending interrupt to serve first.
| D7…D0 | Plain encoder | Priority encoder |
|---|---|---|
| 0000 1000 (D3) | 011 = 3 | 011, V = 1 |
| 0000 0001 (D0) | 000 = 0 | 000, V = 1 |
| 0000 0000 (none) | 000 (looks like D0) | 000, V = 0 |
| 0001 0100 (D4, D2) | 110 = 6 (wrong) | 100 = 4, V = 1 |
| 0110 0010 (D6, D5, D1) | 111 = 7 (wrong) | 110 = 6, V = 1 |
Any function from one block
A mux or a decoder can build any truth table, with no Karnaugh map at all. The page uses F(A, B, C) = Σm(1, 2, 6, 7): F is 1 in rows 001, 010, 110 and 111.
- One 8:1 mux. Connect A B C to the select lines and copy the F column onto the data inputs: I0…I7 = 0 1 1 0 0 0 1 1. Each row of the table is one data input.
- A 4:1 mux and C. Use only A B as the select lines. Each data input now covers two rows with the same A B, and in those rows F is 0, 1, C or C'. Rows 000, 001 have F = 0, 1, so I0 = C. Rows 010, 011 have F = 1, 0, so I1 = C'. Rows 100, 101 give I2 = 0 and rows 110, 111 give I3 = 1.
- A 3:8 decoder and an OR. The decoder makes all eight minterms. OR together the ones where F = 1: F = Y1 + Y2 + Y6 + Y7. The other outputs are not used.
Demo: three builds sets A B C = 110 on each build, and all three give F = 1. On the 8:1 mux it is I6, on the 4:1 mux it is I3 = 1, on the decoder it is Y6. Then A B C = 101 on the decoder raises Y5, which is not wired to the OR, so F = 0.
The mux way grows as 2n data inputs, so it only pays for small functions. It is also exactly how an FPGA works: a lookup table (LUT) is a small memory read through a mux, with the function's truth table stored in it. To find the smallest gate circuit instead, see Karnaugh Maps.
Cascading decoders with enable
The enable input lets small decoders make big ones. Two 2:4 decoders make a 3:8 decoder:
- A1 A0 go to both decoders.
- A2 goes straight to the lower decoder's E, which gives Y4…Y7.
- A2 also goes through a NOT to the upper decoder's E, which gives Y0…Y3.
So A2 = 0 turns on the upper decoder and A2 = 1 the lower one. Only one of them is ever on. Demo: A = 2, then 6 raises output 2 of the upper decoder (Y2), then output 2 of the lower decoder (4 + 2 = Y6). Both decoders see the same A1 A0 = 10, but only the enabled one raises a line. Four 3:8 decoders and one 2:4 decoder, which enables one of them, make a 5:32 decoder in the same way.
Try it
- Pick a block with the tabs. Each tab shows its own setting (size, D, E, type or build) and its main input. Changing either one runs the animation at once.
- Try All Inputs steps through every value of the main input, so you see the whole truth table light up row by row.
- The Demo buttons play the cases above; Undo steps back through them.
See also From Verilog to Hardware for the case statement and ? : operator that synthesis turns into muxes and decoders, Logic Gates for the gates inside each block, and The Single-Cycle MIPS Processor for a datapath where muxes pick the operands and a decoder turns the opcode into control signals.
See also Binary Codes: BCD, Excess-3, Gray and the BCD Adder for a BCD-to-7-segment decoder lighting a display.
What the page leaves out
- Active-low pins. Real chips such as the 74HC138 and 74HC148 use active-low outputs and enables (a 0 means "on"). The page draws everything active-high.
- Gates and timing. Each block switches at once here. Real blocks have a propagation delay and can glitch while the select bits change (see Combinational Logic).
- Tristate muxes. A mux can also be built from tristate buffers on a shared wire. That and the floating value Z are on Multilevel Logic.
- Priority encoder details. Many textbooks write "x" (don't care) for the outputs when V = 0. The page shows 000 there. Chips such as the 74HC148 also have a cascade input and output, so two of them make a 16:4 encoder.
On the mind map
References
Harris and Harris, Digital Design and Computer Architecture, section 2.8 (Combinational Building Blocks): multiplexers, decoders, logic using multiplexers and decoders
Mano and Ciletti, Digital Design, chapter 4 (Combinational Logic): decoders, encoders, priority encoders, multiplexers
Texas Instruments SN74HC138: 3-line to 8-line decoder/demultiplexer
Texas Instruments SN74HC148: 8-line to 3-line priority encoder