1

Lets say I have a number like 12, which would be represented as 1100, and 5, represented as 0101. What would allow me to get the bits to toggle, as in a function such that 12 (Function) 5 would send back every byte of 5 that is 1 switch the bit of 12 in the same space, receiving 1001?

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
Eric Lee
  • 230
  • 1
  • 2
  • 13
  • Possible duplicate of [Bitwise operation and usage](https://stackoverflow.com/questions/1746613/bitwise-operation-and-usage) – AShelly Nov 30 '18 at 19:24

1 Answers1

4

You're talking about an XOR operation (eXclusive-OR) and ^ is the Python operator.

>>> bin(12)
'0b1100'
>>> bin(5)
'0b101'
>>> bin(12 ^ 5)
'0b1001'
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251