We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3eb9da commit cc63532Copy full SHA for cc63532
boolean_algebra/multiplexer.py
@@ -0,0 +1,31 @@
1
+# https://www.electrically4u.com/solved-problems-on-multiplexer/
2
+
3
+def mux(input0: int, input1: int, select: int) -> int:
4
+ """
5
+ Implement a 2-to-1 Multiplexer.
6
7
+ :param input0: The first input value (0 or 1).
8
+ :param input1: The second input value (0 or 1).
9
+ :param select: The select signal (0 or 1) to choose between input0 and input1.
10
+ :return: The output based on the select signal.
11
12
+ >>> mux(0, 1, 0)
13
+ 0
14
+ >>> mux(0, 1, 1)
15
+ 1
16
+ >>> mux(1, 0, 0)
17
18
+ >>> mux(1, 0, 1)
19
20
21
+ if select == 0:
22
+ return input0
23
+ elif select == 1:
24
+ return input1
25
+ else:
26
+ raise ValueError("Select signal must be 0 or 1")
27
28
+if __name__ == "__main__":
29
+ import doctest
30
31
+ doctest.testmod()
0 commit comments