XOR operator

Purpose

The XOR operator works as both a logical and a bitwise arithmetic operator.

Syntax

p XOR q

Remarks

XOR as a logical operator

XOR returns FALSE (zero) if and only if both its operands have the same value.  Here is XOR's truth table:

Truth table

x

y

x XOR y

T

T

F

T

F

T

F

T

T

F

F

F

Using XOR as a bitwise arithmetic operator

An XOR mask complements (reverses) selected bits of an integer-class value, without affecting the other bits of that value.  For example, to complement the two most-significant bits in &H9700, use XOR with a mask of &HC000; that is, all zeros except for the positions to be complemented:

 

See also

Arithmetic OperatorsAND, EQV, IMP, NOT, OR