0

Why print(5^4) shows 1

Why print(5^4) shows 1

2nd Oct 2021, 7:53 AM
Amit Solanki
4 Réponses
+ 6
^ (xor) is a bitwise operator This is what's happening under the hood: 000000100 = 4 000000101 = 5 ^ will evaluate both values, if the bits are the same, 0 is returned, 1 vice versa. 000000001 = 1
2nd Oct 2021, 8:01 AM
Tim
Tim - avatar
+ 3
That helps. Thanks a lot
2nd Oct 2021, 8:02 AM
Amit Solanki
+ 2
Rik Wittkopp Thank you for the compliment
2nd Oct 2021, 9:00 AM
Tim
Tim - avatar
+ 1
Terel Great answer!
2nd Oct 2021, 8:51 AM
Rik Wittkopp
Rik Wittkopp - avatar