Digital Circuits Cheatsheet
Multiplexers and Decoders
Use this Digital Circuits reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Overview
Multiplexers (MUX) and decoders are the two most versatile combinational building blocks. A MUX selects among many data inputs; a decoder activates exactly one of many outputs. Both can implement arbitrary Boolean functions.
Multiplexer Fundamentals
A 2ⁿ-to-1 MUX has: - 2ⁿ data inputs: I₀, I₁, …, I₂ⁿ⁻¹ - n select lines: S₀ … Sₙ₋₁ - 1 output: Y
Y = the data input selected by the binary value of the select lines.
2-to-1 MUX
Y = S′·I₀ + S·I₁
| S | Y |
|---|---|
| 0 | I₀ |
| 1 | I₁ |
4-to-1 MUX
Y = S₁′S₀′·I₀ + S₁′S₀·I₁ + S₁S₀′·I₂ + S₁S₀·I₃
| S₁ | S₀ | Y |
|---|---|---|
| 0 | 0 | I₀ |
| 0 | 1 | I₁ |
| 1 | 0 | I₂ |
| 1 | 1 | I₃ |
8-to-1 MUX (74HC151)
3 select lines (A, B, C); 8 data inputs; active-LOW enable.
| C | B | A | Y |
|---|---|---|---|
| 0 | 0 | 0 | I₀ |
| 0 | 0 | 1 | I₁ |
| 0 | 1 | 0 | I₂ |
| 0 | 1 | 1 | I₃ |
| 1 | 0 | 0 | I₄ |
| 1 | 0 | 1 | I₅ |
| 1 | 1 | 0 | I₆ |
| 1 | 1 | 1 | I₇ |
MUX as a Universal Function Generator
A 2ⁿ-to-1 MUX can implement any n-variable Boolean function by connecting 0 or 1 to each data input (all n variables drive the select lines):
Example: F(A, B) = A ⊕ B using a 4-to-1 MUX (A=S₁, B=S₀):
| S₁ | S₀ | F | → data input |
|---|---|---|---|
| 0 | 0 | 0 | I₀ = 0 |
| 0 | 1 | 1 | I₁ = 1 |
| 1 | 0 | 1 | I₂ = 1 |
| 1 | 1 | 0 | I₃ = 0 |
Shannon expansion (one-variable reduction): implement an n-variable function with a 2ⁿ⁻¹-to-1 MUX by using one variable as the last select line and putting expressions (not just constants) on the data inputs.
Example: F(A,B,C) = Σm(1,2,6,7), use A,B as selects, put C-expressions on inputs:
| A | B | F expression | Data input |
|---|---|---|---|
| 0 | 0 | C | I₀ = C |
| 0 | 1 | C′ | I₁ = C′ |
| 1 | 0 | 0 | I₂ = 0 |
| 1 | 1 | 1 | I₃ = 1 |
MUX Expansion (Building Larger MUXes)
Build a 16-to-1 MUX from four 4-to-1 MUXes and one 4-to-1 MUX as the final stage:
S₁S₀ S₃S₂ (upper select) I₀–I₃ → MUX₀ ─────┐ I₄–I₇ → MUX₁ ──── MUX_final ──── Y I₈–I₁₁ → MUX₂ ─────┘ (S₃S₂) I₁₂–I₁₅→ MUX₃ ─────┘
Demultiplexer (DEMUX)
Routes one input to one of 2ⁿ outputs. A 1-to-4 DEMUX:
| S₁ | S₀ | Y₀ | Y₁ | Y₂ | Y₃ |
|---|---|---|---|---|---|
| 0 | 0 | D | 0 | 0 | 0 |
| 0 | 1 | 0 | D | 0 | 0 |
| 1 | 0 | 0 | 0 | D | 0 |
| 1 | 1 | 0 | 0 | 0 | D |
A decoder with the data signal on its enable line is a DEMUX.
Decoder Fundamentals
An n-to-2ⁿ decoder has n inputs and 2ⁿ outputs. Exactly one output is active at a time.
2-to-4 Decoder
| EN | A₁ | A₀ | Y₀ | Y₁ | Y₂ | Y₃ |
|---|---|---|---|---|---|---|
| 0 | X | X | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Equations (active-HIGH): Yᵢ = EN · (minterm i)
3-to-8 Decoder (74HC138)
- 3 address inputs: A, B, C
- 8 active-LOW outputs: Y̅₀ – Y̅₇
- 3 enable inputs: G1 (active-HIGH), G̅2A, G̅2B (both active-LOW)
- Active when: G1=1, G̅2A=0, G̅2B=0
Y̅ᵢ = 0 when enabled and address = i Y̅ᵢ = 1 otherwise
Decoder as Function Generator
Connect decoder outputs (minterms) to an OR gate → any SOP function.
Example: F(A,B,C) = Σm(0,3,5,6)
3-to-8 decoder: Y₀ ──┐ Y₃ ──┤ OR ──── F Y₅ ──┤ Y₆ ──┘
With active-LOW outputs (74HC138), use a NAND instead of OR (De Morgan).
Decoder Expansion
Build a 4-to-16 decoder from two 3-to-8 decoders:
MSB (A₃) ────────────────── EN (decoder_HIGH): selects upper 8 outputs A₃′ ─────────────────────── EN (decoder_LOW): selects lower 8 outputs A₂, A₁, A₀ ─── both decoders' address inputs
| A₃ | Active decoder |
|---|---|
| 0 | Lower (outputs Y₀–Y₇) |
| 1 | Upper (outputs Y₈–Y₁₅) |
MUX vs Decoder Comparison
| Feature | MUX | Decoder |
|---|---|---|
| Inputs | n selects + 2ⁿ data | n address + EN |
| Outputs | 1 | 2ⁿ |
| Function | Route one data input to output | Activate one of 2ⁿ outputs |
| As logic block | Any function (data inputs = constants) | Any SOP (OR output minterms) |
| Typical use | Bus routing, data selection, function gen | Address decoding, memory CS, demux |
Common ICs
| Part | Type | Description |
|---|---|---|
| 74HC151 | 8-to-1 MUX | 3 selects, complementary outputs |
| 74HC153 | Dual 4-to-1 MUX | Two independent 4-to-1 MUXes |
| 74HC157 | Quad 2-to-1 MUX | 4 independent 2-to-1 MUXes |
| 74HC138 | 3-to-8 decoder | Active-LOW outputs, 3 enables |
| 74HC139 | Dual 2-to-4 decoder | Two independent decoders |
| 74HC154 | 4-to-16 decoder | Active-LOW outputs |
Tri-State Buffers and Bus MUX
Tri-state (3-state) buffer: output can be HIGH, LOW, or high-impedance (Z).
Used to share a common bus among multiple sources:
Device A ── tri-state buffer ──┐ Device B ── tri-state buffer ──┤─── shared bus Device C ── tri-state buffer ──┘ Only one enable is asserted at a time.
| EN | Input | Output |
|---|---|---|
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| 0 | X | Z |