I cant understand

Define a function called flip_bit that takes the inputs (number, n).
Flip the nth bit (with the ones bit being the first bit) and store it in result.
Return the result of calling bin(result).

def flip_bit(number,n):
mask=0b1 << n
result=number ^ mask
return bin(result)

Can any one please tell me what is the fault?


Can you see that when I shifted 0b1 to the left (10 shifts) but it shifted to the 11th place?

Same thing is happening with this line..
mask=0b1 << n
It shifts to left at n+1th position


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.