Operator
Xor
Usage
result = expression1 Xor expression2
Part |
Description |
---|---|
result |
A Boolean value if expression1 and expression2 are Boolean; an Integer value if expression1 and expression2 are integers. |
expression1 |
Any valid Boolean or Integer expression. The data types of expression1 and expression2 must match. |
expression2 |
Any valid Boolean or Integer expression. The data types of expression1 and expression2 must match. |
Notes
If you use Xor with two booleans, it returns the logical Xor of the booleans. The result table for Xor, Or, and And is:
Expression1 |
Expression2 |
Xor |
Or |
And |
---|---|---|---|---|
True |
True |
False |
True |
True |
True |
False |
True |
True |
False |
False |
True |
True |
True |
False |
False |
False |
False |
False |
False |
If you use Xor with two booleans, it returns True if the booleans are not equal. The logic is "Not (a=b)". The result is a boolean.
When you pass two integers, it returns an integer that is the result of comparing each bit of the two integers passed and assigning 1 to the bit position in the integer returned if both bits in the same position in the integer passed are not equal. Otherwise, 0 is assigned to the bit position. In this case, it is equivalent to using the BitXor method of the Bitwise class.
The following table shows the results:
Integer1 |
Integer2 |
BitAnd |
BitOr |
BitXor |
---|---|---|---|---|
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
Sample code
This example does a bitwise Xor on the two integers passed.
Var i As Integer
I = 5 Xor 3 ' returns 6
Compatibility
All project types on all supported operating systems.
See also
And, Not, Or operators; Bitwise class; Operator And function; Operator precedence