It isn't working python


#1

a = 0b11101110
mask = 0b00010001
desired = a ^ mask
print bin(a ^ mask)
It is still showing this error Make sure your answer is a binary string.


#2

The point of the exercise is to flip the bits in a. What does that mean? Hmm, think about it. It means to turn the 1s into 0s and 0s into 1s.

You’re giving that

a = 0b11101110 and once you apply the mask, it should flip the bits to be:

a = 0b00010001.

Do you see now what flipping the bits results in? If no, ask me and we’ll go further.

If yes, next you need to set the mask to a binary value that when you use XOR ^ it flips the bits.

What did you learn about XOR? Here’s the truth table:

So remember, for every given bit in a and b:

0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

0 ^ 1 = 1 So if a bit is 0 and the mask bit is 1, then the bit flips. Right? It becomes a 1.

1 ^ 0 = 0 So if a bit is 1 and the mask bit is 0, then the bit flips. Right? It becomes a 0.

Now use that logic to layout the bits in the mask.


#3

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