Just Flip out help needed


#1

So I'm trying to flip a and it keeps saying to make sure it's in a binary string. Can someone explain why this isn't working?

a = 0b11101110
mask = 0b10010010
print str(bin(a ^ mask))


#2

You don't need to use str(bin(a ^ mask)) to get string. A bin() function already returns a string.

Are you using variable values from example?


#3

@arkussss I am but I get the same error when I don't use the string function.


#4

Check your mask value. I think this is a problem. It doesn't flip all bits.


#5

It might also not be asking you to print anything, so if that's the only way that you're presenting the result, then it'll be looking elsewhere.


#7

I am getting "Oops, try again. Make sure your answer is a binary string.", although the result displayed is in Binary format (0b11111111), can someone help me explain whats wrong with my code? My code is given below.

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


#8

Ok so I did figure it out after talking with a programmer I know. In order to flip the code. The item used to flip the function should be all 1's. So we would set mask to 0b11111111


#9

I'm new to programming as well and this is the XOR (^) explanation from codecademy:
"The XOR (^) or exclusive or operator compares two numbers on a bit level and returns a number where the bits of that number are turned on if either of the corresponding bits of the two numbers are 1, but not both"
So basically
0 ^ 1 = 1
0 ^ 0 = 0
1 ^ 1 = 0
1 ^ 0 = 1
0 goes to 1 and 1 goes to 0 if your mask is all 1
Hopefully that helps


#10

I've got the same problem, and I found just now we need to set mask=0b11111111,and it works


#11

I got the same problem!!


#12

this my code
a = 0b11101110
mask = 0b11111111
print bin(mask ^ a)


#13

Guys ... I don't understand. How come you can make mask 0b and bunch of ones when hint clearly says you should use << ? What's catch here ?