Search code examples
bitwise-operatorsxor

what does XOR with non-binary numbers do?


For example,

0^1 will return 1 and

1^1 will return 0

This has it's obvious uses for flipping bits.

However, I have seen applications of XOR such as

55^4 or 73^1

I don't understand what the purpose of this is. Isn't it just checking that 55 and 73 are not equal to 4 and 1 respectively?


Solution

  • It will convert both the numbers to binary number first and then apply bitwise XOR for all the bits

    55 -> 110111
    4  -> 000100
    Xor-> 110011  ->which is equal to decimal 51.