File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ 1
18
+ >>> mux(1, 0, 1)
19
+ 0
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 ()
You can’t perform that action at this time.
0 commit comments