To toggle bit k (flip 0 to 1 or 1 to 0) in number n, you XOR n with 2k. In code: n∧(1<<k).
XOR flips bits because 0∧1=1 and 1∧1=0. When you XOR with a 1, that bit flips. When you XOR with a 0, the bit stays the same.
Example: Toggle bit 1 in 12=1100. Compute 12∧2=1100∧0010=1110=14. Bit 1 flipped from 0 to 1. Toggle again: 14∧2=1100=12. It's back.