Reputation: 13
So I've made a Python module that adds all seven logic gates (NOT, OR, AND, NAND, NOR, XOR, XNOR.)
Please note that it does not look like
a AND b
it instead looks like
And(a, b)
In a program I'm trying to make, I need a logic gate with three inputs: A, B and C. the gate should return whatever A is if C is false. However, if C is true, it should return whatever B is. It does not matter if A and B are the same. I don't want to use actual if's.
Upvotes: 1
Views: 656
Reputation: 114310
If you are trying to create a multiplexer gate from the logic gates you have defined, here is a great article on the subject: http://improve.dk/creating-multiplexers-using-logic-gates/.
Basically, you do this:
def MUX(A, B, C):
return OR(AND(A, C), AND(B, NOT(C)))
In Python notation, this would look like (A & C) | (B & ~C)
.
If C
is True
, the result is A
. If C
is False
, the result is B
.
Upvotes: 1
Reputation:
Do you want this :
Here you have your C instant of SEL. The out is your MULTIPLEXER return
so in python
def MULTIPLEXER(A,B,C):
if(C):
return B
else:
return A
Upvotes: 0
Reputation: 137398
Is this what you're looking for?
def MUX(A, B, C):
return B if C else A
Upvotes: 0