boolean_algebra.multiplexer

Functions

mux(→ int)

Implement a 2-to-1 Multiplexer.

Module Contents

boolean_algebra.multiplexer.mux(input0: int, input1: int, select: int) int

Implement a 2-to-1 Multiplexer.

Parameters:
  • input0 – The first input value (0 or 1).

  • input1 – The second input value (0 or 1).

  • select – The select signal (0 or 1) to choose between input0 and input1.

Returns:

The output based on the select signal. input1 if select else input0.

https://www.electrically4u.com/solved-problems-on-multiplexer https://en.wikipedia.org/wiki/Multiplexer

>>> mux(0, 1, 0)
0
>>> mux(0, 1, 1)
1
>>> mux(1, 0, 0)
1
>>> mux(1, 0, 1)
0
>>> mux(2, 1, 0)
Traceback (most recent call last):
    ...
ValueError: Inputs and select signal must be 0 or 1
>>> mux(0, -1, 0)
Traceback (most recent call last):
    ...
ValueError: Inputs and select signal must be 0 or 1
>>> mux(0, 1, 1.1)
Traceback (most recent call last):
    ...
ValueError: Inputs and select signal must be 0 or 1