binutils.py 183 B

123456
  1. # takes two bits and adds them, respecting possible carryins
  2. def add(b1, b2, c):
  3. result = (b1 ^ b2) ^ c
  4. carryout = (b1 & b2) | (b2 & c) | (b1 & c)
  5. return result, carryout