# takes two bits and adds them, respecting possible carryins def add(b1, b2, c): result = (b1 ^ b2) ^ c carryout = (b1 & b2) | (b2 & c) | (b1 & c) return result, carryout