Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created October 15, 2010 09:39
Show Gist options
  • Select an option

  • Save oskimura/627912 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/627912 to your computer and use it in GitHub Desktop.
bitsPlus.py
def harfAdder(a, b):
s = a ^ b
c = a & b
return (c,s)
def fullAdder(a,b,x):
(c1, s1) = harfAdder(a,b)
(c2, s2) = harfAdder(s1,x)
return ((c1|c2),s2)
def plus(seq1, seq2):
c = 0
n = len(seq1)
i = 0
results = []
while i<n :
a = seq1[i]
b = seq2[i]
(c1,s) = fullAdder(a,b,c)
c = c1
print c
results.append(s)
i=i+1
results.append(c)
return results
print plus([1,1,1],[1,0,0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment