Sum of Two Integers
x, y = abs(a), abs(b)
if x < y:
return self.getSum(b, a)
if a == 0:
return b
if b == 0:
return a
if a > 0 and b > 0 or a < 0 and b < 0:
while y:
x, y = x ^ y, (x & y) << 1
else:
while y:
x, y = x ^ y, ((~x) & y) << 1
return x if a > 0 else -xx ^ yfor addition without carry,x & ycalculates carry.(~x) & ycalculates the borrowing, whenx == 0andy == 1.- Iterate to calculate each bit