- 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).
So this is my code.
>>>> mask = (0b1<<n-1)
>>>> number = int(number,2)
>>>> result = mask^number
>>>> print bin(result)
It works fine on my compiler but for some reason I get an error. Could anyone tell me what is wrong?
Oops, try again. Does your flip_bit function take exactly two arguments (a binary number and the bit to flip)? Your code threw a "int() can't convert non-string with explicit base" error.