XOR

The XOR function is used to perform a logical exclusion on two numbers.

Syntax

result = A XOR B

Remarks

The XOR operator performs a bit-wise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following truth table:

If bit in              And bit in         The result

A is                   B is                  is

1                       1                      0

1                       0                      1

0                       1                      1

0                       0                      0

Although XOR is a bit-wise operator, it is often used to test Boolean (True/False) conditions. 0 is false and any non-zero number is true. Because XOR is a bit-wise operation, it is possible to XOR two non-zero numbers (e.g., 2 and 4) and get a non-zero number. (XOR will only operate with two non-zero numbers and return 0 if the original numbers are equal.)

If                       And                  Then

A is                   B is                  Result is

-1                      -1                     0

-1                      NAN                 NAN

0                       Any Number      Number2

0                       NAN                 NAN

NAN = Not a number

Expressions that are evaluated to a number can be used in place of one or both of the numbers.