The XOR logical operation, or exclusive or, takes two boolean operands and returns true if and only if the operands are different. Thus, it returns false if the two operands have the same value. So, the XOR operator can be used, for example, when we have to check for two conditions that can’t be true at the same time.
What is XOR in coding?
XOR is a bitwise operator, and it stands for “exclusive or.” It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).
How do you XOR an array?
- Create a variable to store the XOR of the array as a result.
- For each element in the array, find the XOR of the element and the result variable using ‘^’ operator.
- Finally, the result variable stores the XOR of all elements in the array.