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.

# It isn't working python

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

`1`

s into `0`

s and `0`

s into `1`

s.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`

.

**system**#3

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