2 ms·
And if you need to handle negatives: def add(a, b): while a and b: if a ^ b < 0: (a, b) = (a & ~b, b & ~a) (a, b) = (a ^ b,
by recursive 10y ago
And if you need to handle negatives:
def add(a, b):
while a and b:
if a ^ b < 0: (a, b) = (a & ~b, b & ~a)
(a, b) = (a ^ b, (a & b) << 1)
return a or b