+ 2

# XOR in python

Its not how the XOR operator is done? https://code.sololearn.com/cPOQua785Saq/?ref=app

1st Oct 2018, 10:54 PM
I Am Arthur
4 ответов
+ 2
You have to put paranthese around the expressions, like this: (x==y) ^ (y==y) Then you will have 0 or 1 (false or true), boolean/binary values. Otherwise cases ⏩ Prometheus ⏪ mentioned will happen. All values are stored in binary, the computer only knows binary. We just have a representation in decimal, because we have 10 fingers and are used to it. Like in decimal we can write it like this: 543 = 5*100 + 4 *10 + 3*1 we can also represent a number in binary: 6 = 0*8 + 1*4 + 1*2 + 0*1 so 6 is 0110 in binary
2nd Oct 2018, 2:12 AM
Matthias
+ 1
Just to let you know, if a = 1 and b = 2, a: 0 0 1 b: 0 1 0, then c = a^b will be: c: (0^0) (0^1) (1^0), which is basically, c: 0 1 1, or 3.
1st Oct 2018, 11:27 PM
👑 Prometheus 🇸🇬
+ 1
⏩ Prometheus ⏪ How fo u know how is the number in binnary?
1st Oct 2018, 11:38 PM
I Am Arthur
+ 1
What are you trying to do? if x == x ^ y == y: print("Both true") x == x and y == y will be true (or 1) for any numbers x and y, but 1 ^ 1 will be 0, so it doesn't tell you that both expressions are true... Using a xor b to find out if a and b are both true or false isn't possible. a xor b is false if a and b are equal. But you still don't know if they're both true or both false. You could do something like if a and not (a^b) to find out if both a and b are true.
2nd Oct 2018, 5:34 AM
Anna
Актуальное сегодня
Be honest