bit-manipulationcomplement

What is long version of a Common Bitwise Operation?


BitField1 = 00100110

BitField2 = 00110011

((BitField1 & ~BitField2) | (BitField2 & ~BitField1)); = 00010101

So this is the long version of a common bitwise operation, what is it?

Want to understand if above bit operation is some known operation ?


Solution

  • This is XOR. You end up with a 1 in those bits where either BitField1, or BitField2, but not both, have a 1.

    As Wikipedia says, one use is

    "Assembly language programmers sometimes use XOR as a short-cut to setting the value of a register to zero. Performing XOR on a value against itself always yields zero."