Search code examples
javascriptxor

Reverse XOR operator in JavaScript?


I have 2 variables, x and y.

I am doing z = x^y.

Now assuming I know only z and y, How can I get x back? Is there an opposite to ^ in JavaScript?


Solution

  • Yes, ^ is its own inverse.

    x == (x^y)^y