Created
October 15, 2010 09:39
-
-
Save oskimura/627914 to your computer and use it in GitHub Desktop.
bitsPlus.py
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 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]) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bitごとの足し算
一番右が最上位bit