|
October 17, 1999 The Bitwise XOR Operator Tips: October 1999
Yehuda Shiran, Ph.D.
|
|
The bitwise XOR (exclusive OR) operator compares two bits and assign 1 to the result when the two operands are different. Here is the truth table for this operator:
The XOR operator, like all other bitwise operators, can take only numeric values as its operands. Since JavaScript does not support bit-length variables, you have to do your bitwise math with byte-length operands, i.e. with integers that are less than 256. Any operand longer than a byte (greater than 255) will be chopped and only the LSB (Least Significant Byte) will be used. Let's do a simple calculation:
People who read this tip also read these tips: Look for similar tips by subject: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||