Why isn't this working? Python


a = 0b11101110
mask = 0b1
print bin(0b11101110 ^ 0b1)

Make sure your answer is a binary string.= error


First tip is to use the variables you assigned when printing:

print bin(a ^ mask)

Next, I assume you are on the 13. Just Flip Out of the Introduction to Bitwise Operators lesson. Right?

Goal -> You want to flip the bits of a to make the 1s 0 and the 0s into 1s.

Think about that. Right now, a = 0b11101110. After flipping the bits, you’d have 0b00010001 which can also be written as 0b10001.

How would you do that using XOR and a mask? Think about what XOR does. And check out the Hint in the lesson too as it will help you.


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