xor python code example
Example 1: xor in python
a = 60
b = 13
c = 0
c = a & b;
print "Line 1 - Value of c is ", c
c = a | b;
print "Line 2 - Value of c is ", c
c = a ^ b;
print "Line 3 - Value of c is ", c
c = ~a;
print "Line 4 - Value of c is ", c
c = a << 2;
print "Line 5 - Value of c is ", c
c = a >> 2;
print "Line 6 - Value of c is ", c
Example 2: how to use xor in python
"text" ^ key
num ^ key
Example 3: how to calculate binary AND, OR, XOR in python
>>>
>>> a = 2
>>> b = 8
>>> a ^= b
>>> b ^= a
>>> a ^= b
>>> a
8
>>> b
2