toggle_bits(flags, mask) that returns flags with every bit set in mask flipped (on bits turned off, off bits turned on), using the bitwise XOR operator ^. Also write find_unique(numbers) that, given a list numbers where every value appears exactly twice except for one value that appears exactly once, returns that unique value in O(n) time using XOR (no counting dict).toggle_bits(0b1010, 0b0110)
12
0b1010 ^ 0b0110 = 0b1100 = 12.
find_unique([4, 1, 2, 1, 2])
4
XOR-ing all values cancels out pairs, leaving 4.
XOR-ing a bit with 1 flips it, XOR-ing with 0 leaves it unchanged — that is exactly what `flags ^ mask` does.
For find_unique, XOR-ing a value with itself yields 0, and XOR is associative/commutative, so XOR-ing the whole list cancels every pair.