Slip an slie


Please have a look at my code below.
I expect that 100(number after shifting ob1 two to the left)^010(mask) = 0b110but codecademy will not accept this result but instead expects 0b101 which it accepts when number = 0b1<<2 is commenred out.
Question is What is the difference in values between number = 0b100 and 0b1 in the llast print statement

Replace this line with your code. 
def flip_bit(number, n):
    mask = 0b1<<n-1#checking 1
    print bin(mask)#checking1a
    number = 0b1<<2 #checking 2
    print bin(number)#checking 2a
    result = number^mask
    return bin(result)
print flip_bit(0b1, 2)


When we shift bits left, we do not change any of the bits except to add a zero on the right.

0b10 << 1 == 0b100


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