Home  >  Article  >  Web Front-end  >  Introduction to the use of bitwise "XOR" operator in JavaScript_javascript tips

Introduction to the use of bitwise "XOR" operator in JavaScript_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:55:361993browse

The bitwise XOR operator (^) performs a bitwise XOR on two expressions. Usage:

Copy code The code is as follows:

result = expression1 ^ expression2

where result is any variable.
expression1 is any expression.
expression2 is any expression.

Bitwise XOR operator description
^ operator looks at the binary representation of the values ​​of two expressions and performs a bitwise XOR. The result of this operation is as follows:

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

if and only if only When a bit of an expression is 1, the result will be 1. Otherwise this bit of the result is 0.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn