blob: cf8e36ad7b03ff4654a5c269225cd03c59f09fca (
plain)
1
2
3
4
5
6
7
8
9
|
def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos)))
|