Hi I am not getting how the flipping is done when we do not know whether the original number has 1 or 0 at the tenth place to flip.
1 ^ 1= 0
0 ^ 1= 1
How do we
And i got the answer while typing the above 2 lines!
Whenever you do a XOR operation of any number with 1 , the original no gets flipped ! cheers!
def flip_bit(number, n):
mask = (0b1 << (n-1))
result = bin(number ^ mask)