Bitwise XOR '^', '^='

The Bitwise XOR operator performs a bitwise XOR of the bits of the first operand with the bits of the second operand. Bitwise XOR can be used in both variable and integer constant expressions, but not in floating-point constant expressions. 

Each bit of the two operands is subject to the following logic:

Bitwise XOR Truth Table

A

B

Result

0

0

0

0

1

1

1

0

1

1

1

0

Example:

X := %00101100 ^ %00001111

The above example XORs %00101100 with %00001111 and writes the result, %00100011, to X.

Bitwise XOR has an assignment form, ^=, that uses the variable to its left as both the first operand and the result destination. For example,

X ^= $F      'Short form of X := X ^ $F

Here, the value of X is XORed with $F and the result is stored back in X. The assignment form of Bitwise XOR may also be used within expressions for intermediate results; see Intermediate Assignments.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.