2. Circuits and Plexers
Adders
Let's say we want to add two numbers, first we need to make the truth table for each bit addition.
Notice that We must consider a carry in and a carry out.
$C_{out}=\bar{A}BC_{in}+A\bar{B}C_{in}+AB\bar{C_{in}}+ABC_{in}$
$S=\bar{A}\bar{B}C_{in}+\bar{A}B\bar{C_{in}}+A\bar{B}\bar{C_{in}}+ABC_{in}$
We have a one-bit full adder at our use.
Now let's chain them together to make them useful.
For substraction, just negate B and add one to the carry in.
Plexers
A multiplexer (mux) outputs one of its inputs based on the select.
Think of a multiplexer as a hardware if-else statement.
A demux does the opposite. Sending an input to one of the outputs.
An encoder takes $2^n$ inputs into n outputs. So, it tells you which input is one.
But wait, this could result in an invalid result, so it has an additional output valid
.
We could just use a priority encoder!
X means we don't care what the result is.
All zeros is still an invalid input!
A decoder is like a 1-bit demux with an input of 1.