# Multiplexer
**A circuit that selects an input from several and forwards it to a single output.**
A *multiplexer* or mux of $2^{n}$ *information* inputs has $n$ *select* lines. The inputs are labelled according to the binary combination of the select lines.
The inverse of a multiplexer is a [[demultiplexer]].
> [!Example] 4-to-1-line multiplexer
> $Z=(I_{0}\bar{S_{0}}\bar{S_{1}})+(I_{1}S_{0}\bar{S_{1}})+(I_{2}\bar{S_{0}}S_{1})+(I_{3}S_{0}S_{1})$
>
> | $S_1$ | $S_0$ | $Z$ |
> |:-----:|:-----:|:-----:|
> | $0$ | $0$ | $I_0$ |
> | $0$ | $1$ | $I_1$ |
> | $1$ | $0$ | $I_2$ |
> | $1$ | $1$ | $I_{3}$ |
>
> ![[4to1Multiplexer.svg|300]]
A multiplexer can be implemented using a [[decoder]], $2$-input AND gates, and an OR gate.
> [!Example] 4-to-1-line multiplexer construction
> ![[4to1MultiplexerConstruction.svg]]
## Cascading multiplexers
Larger multiplexers are implemented by *cascading* smaller multiplexers.
> [!Example] 8-to-1 cascading multiplexers
> The following is an 8-to-1 multiplexer constructed from two 4-to-1 line multiplexers into a 2-to-1 line multiplexer.
>
> ![[8to1CascadingMultiplexers.svg|500]]
## Applications
Multiplexers can be used to implement [[Boolean Function|Boolean functions]]. The functions need to be *decomposed* with [[Boole's expansion theorem]] first, such that a variable or a set of variables can act as the select lines.
> [!Boolean equation, 1 select line]
>$\begin{flalign}
F&=\bar{A}\bar{C}+AB+AC &\\
&=A(B+C)+\bar{A}(\bar{C})
\end{flalign}$
![[MultiplexerImplementationBooleanEquation1.svg|500]]
> [!Boolean equation, 2 select lines]
To use both $A$ and $B$ as select lines, $B$ needs to be included in every term. This can be achieved by multiplying all terms by $B+\bar{B}=1$.
>$\begin{flalign}
F&=\bar{A}\bar{C}+AB+AC &\\
&=AC(B+\bar{B})+AB(1)+\bar{A}\bar{C}(B+\bar{B}) &\\
&=ABC+A\bar{B}C+AB(1)+\bar{A}B\bar{C}+\bar{A}\bar{B}\bar{C} &\\
&=AB(1)+A\bar{B}(C)+\bar{A}B(\bar{C})+\bar{A}\bar{B}(C)
\end{flalign}$
![[MultiplexerImplementationBooleanEquation2.svg|550]]
> [!Minterm canonical form]
$F(A,B,C,D)=\sum m(1,3,4,11,12,13,14,15)$
>
If $A$ and $B$ are the select lines, a [[Karnaugh Map|K-map]] can be used to find the combinations of the other variables that correspond with each input, i.e. $AB = 00$, $AB=01$ etc.
>
For example, if $AB=01$, then the minterm $\bar{C}\bar{D}$ is HIGH according to the function. Thus, $\bar{C}\bar{D}$ must be the value forwarded to the output when $AB=01$.
>
![[MultiplexerImplementationMintermCanonicalKMap.svg|400]]
>
![[MultiplexerImplementationMintermCanonical.svg|550]]