The XOR (^) operator is quite commonly used to solve binary problems, these are some important properties you should familiarize yourself with:
n ^ n = 0
n ^ m == m ^ n
n ^ (m ^ k) == (n ^ m) ^ k
n ^ 0 = n
Common bitmasks
Bitmasks are commonly used to "force" a certain set of bits to be used. They are also used to constraint Python's numbers as Python doesn't use 32 bits for integers so using a manual bitmask is necessary for constraining it
Retrieving the upper 16 bits: 0xffff0000
Retrieving the lower 16 bits: 0x0000ffff
Retrieving all bits in groups of 4: 0xff00ff00
Retrieving all bits in groups of 2: 0xcccccccc
Retrieving all single bits: 0xaaaaaaaa
Techniques
Test is bit K is set: num & (1 << k) != 0
Set bit K: num |= (1 << k)
Turn off bit K: num &= ~(1 << k)
Toggle bit K: num ^= (1 << k)
Multiply by 2K: num << k
Divide by 2K: num >> k
Check if number is power of 2: (num & num - 1) == 0 or num & (-num) == num