Introduction to the use of bitwise xor operators in JavaScript

  • 2020-03-30 02:23:37
  • OfStack

The bitwise xor operator (^) performs bitwise xor on two expressions. Usage:
 
result = expression1 ^ expression2 

Where result is any variable.
Expression1 is any expression.
Expression2 is any expression.

Description of the bitwise xor operator
The ^ operator looks at the value of the binary representation of two expressions and performs bitwise xor. The result of this operation is as follows:

0101 (expression1)
1100 (expression2)
----
1001 (result)

The resulting bit is 1 if, and only if, one of the members of an expression is 1. Otherwise the resulting bit is 0.

Related articles: