2 ms·
Basically replicate the carry process in the form of bit ops: def inc(n): x = 1 while n & 1 == 1: n = n >> 1 x = x
by veyron 15y ago
Basically replicate the carry process in the form of bit ops:
def inc(n):
x = 1
while n & 1 == 1:
n = n >> 1
x = x << 1
n = n | 1
while not x == 1:
x = x >> 1
n = n << 1
return n