Created
April 13, 2012 14:20
-
-
Save codesburner/2377217 to your computer and use it in GitHub Desktop.
Simple Logic gates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def NOT(a): | |
return (1 - a) | |
def AND(a,b): | |
return a * b | |
def OR(a,b): | |
return a + b | |
def NAND(a,b): | |
return NOT(AND(a,b)) | |
def NOR(a,b): | |
return NOT(OR(a,b)) | |
def XOR(a,b): | |
x = OR(a,b) | |
y = NAND(a,b) | |
return AND(x,y) | |
def halfAdder(a,b): | |
x = XOR(a,b) | |
y = AND(a,b) | |
return x,y | |
def fullAdder(a,b,c): | |
x = halfAdder(a,b) | |
y = halfAdder(x[0],c) | |
z = OR(x[1], y[1]) | |
return (y[0],z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment