0
PYTHON ~ operator: a=60,b=12,c=4,d=1. print(a^b|~c^d)
a=60,b=12,c=4,d=1. print(a^b|~c^d) Can someone explain the logic. Especially ~ operator. Thanks 1) 53.0 2)-2.0 3)-6.0 4)-5.0
1 ответ
+ 14
^ : XOR
~ : bit reverse
you first convert numbers to binary and then follow this logic for XOR : one or other but not both
5 ^ 7 =
101 ^ 111 =
101 ^
111 =
010 = 2
the ~ negates all bits and the signum aswell.
It usually returns:
~a = -(a+1)
~2 = -3