Please keep in mind that C operates at a much higher level of abstraction than logic gates, so such comparisons can lead to confusion. However, the closest you can come to the demultiplexer (I will start from this, as it is easier) is the left shift operator:
a << b
This expression, assuming that a and b are int expressions, will create a new int whose bits are bits a shifted left b times. For example, if a is 0100011011010110 , and b is 3, the result is 0011011010110000 . Now, if a is either 0 or 1, and you interpret the resulting integer as a bus, this corresponds to the demultiplexer.
The multiplexer / selector can be implemented by the right shift operator >> , which shifts the bits to the right. However, the result should be & 'ed with 1 to clear any other bits than the one you are interested in:
(c >> b) & 1
This effectively selects the bit with index b (starting with the least significant bit) from c .
source share