Flip and slide



It doesn't work

def flip_bit(number , n):
    result = (number ^ n)
    return bin(result).

OUTPUT : Oops, try again. Your function fails on flip_bit('0b1010101', 3). It returns "0b1010110" when it should return "0b1010001"
Can somebody explain the subject to me how ^ and | and & work? I don't understand it, I read the info Codecademy's exercises wrote but I didn't really get it


You need to create a variable mask that flips the bitwise operator and stores that operation in a variable result that includes your number variable along with the mask,

mask = (0b1 << n-1)
result = number ^ mask


Already passed it but thanks anyway


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