python XOR operator
XOR bitwise logical operator '^'
xor return 0 if both values are the same and 1 if different. i.e if exactly one bit is set to 1
working with intergers:
- returns 0 if numbers are the same
- n ^ 0 = n
- xor operation
0001 xor 0010 = 0011
0100 xor 0101 = 0001
xor es asociativo y conmutativo(igual que la suma)
trick to get the last set bit (rightmost set bit):
rightmostSetBit = val & -val
& returns true if a single bit of all the bits in the two compared values are both set
or maybe just the rightmost one?
100 & 101 == true
100 & 100 == true