Simulate a MUX or a DEMUX and implement any logic function with a multiplexer
Equation:
Click the values in column Y to define the function and choose how you want to build it.
A multiplexer (MUX) is a digital selector switch: it has 2n data inputs, n select inputs and one output. The binary number on the select lines decides which input reaches the output. A 4:1 MUX has 4 inputs D0 to D3 and two select bits S1 S0; with S1 S0 = 10 the output copies D2. Its equation is a sum of products in which each term lets one data input through:
Most ICs also have an enable input (usually active low): when it is not active, the output stays at 0 or in high impedance, which allows several MUXes to be combined into a larger one.
The demultiplexer does the opposite: one data input and 2n outputs. The select lines decide which output receives the data and the others stay inactive. If the data input is tied to 1, the demultiplexer becomes an n to 2n decoder: it activates a single output according to the binary code. That is why the 74HC138 is sold as a «3 to 8 decoder/demultiplexer» and is used both to route a signal and to select memories or peripherals on a bus.
A MUX can generate any logic function without simplifying it. With all variables on the select lines, each input Di is tied to 0 or 1 according to row i of the truth table: it is the most direct method, but 4 variables need a 16:1 MUX.
With the last variable as data, a MUX of half the size is enough. The other variables drive the select lines and, for each pair of rows that differ only in the last variable X, the corresponding input is tied to 0, 1, X or X' according to the two values of the function. This way a 3-variable function fits in a 4:1 MUX and a 4-variable one in a 74HC151 (8:1).
| IC | Function | Notes |
|---|---|---|
| 74HC157 | Quad 2:1 MUX | Common select; handy to choose between two 4-bit buses |
| 74HC153 | Dual 4:1 MUX | Common select and independent enables |
| 74HC151 | Single 8:1 MUX | True and inverted outputs |
| 74HC251 | Single 8:1 MUX | Three-state output for shared buses |
| 74HC138 | 3 to 8 decoder / DEMUX | Active-low outputs and three enable inputs for cascading |
| 74HC139 | Dual 2 to 4 decoder / DEMUX | Active-low outputs |
| 74HC4051 | 8:1 analog MUX/DEMUX | Switches analog signals in both directions; widely used to add inputs to a microcontroller ADC |
On a microcontroller, a 74HC4051 lets you read 8 sensors with a single analog input and three digital pins; a 74HC138 activates one of eight outputs with three pins. To expand digital outputs that must stay on at the same time, shift registers (74HC595) are used.
Related: logic gate simulator (includes a 2:1 MUX made of gates), BCD to 7-segment decoder and Karnaugh map.