Skip to content

Instantly share code, notes, and snippets.

@codesburner
Created April 13, 2012 14:20
Show Gist options
  • Save codesburner/2377217 to your computer and use it in GitHub Desktop.
Save codesburner/2377217 to your computer and use it in GitHub Desktop.
Simple Logic gates
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