X or (operator)

Syntax expression1 Xor expression2
Description Performs a logical or binary exclusion on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or NULL variants, then a logical exclusion is performed as follows:
If the first expression is and the second expression is then the result is
TRUE TRUE FALSE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE
If either expression is Null , then Null is returned. Binary Exclusion If the two expressions are Integer, then a binary exclusion is performed, returning an Integer result. All other numeric types (including Empty variants) are converted to Long, and a binary exclusion is then performed, returning a Long result. Binary exclusion forms a new value based on a bit-by-bit comparison of the binary representations of the two expressions according to the following table:
1 Xor 1 = 0 Example
0 Xor 1 = 1 5??01101001
1 Xor 0 = 1 6??10101010
0 Xor 0 = 0 Xor????11000011
Example This example builds a logic table for the XOR function and displays it.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
????msg1 = "Logic table for Xor:" & crlf & crlf
????For x = -1 To 0
????????For y = -1 To 0
????????????z = x Xor y
????????????msg1 = msg1 & CBool(x) & " Xor "
????????????msg1 = msg1 & CBool(y) & " = "
????????????msg1 = msg1 & CBool(z) & crlf
????????Next y
????Next x
????MsgBox msg1
End Sub
See Also Operator Precedence (topic); Or (operator); Eqv (operator); Imp (operator); And (operator).