Operator

# Xor

<div class="rst-class">

forsearch

</div>

Operator

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Performs a logical <span class="title-ref">Xor</span> operation on `booleans</api/data_types/boolean>` and a bitwise <span class="title-ref">Xor</span> operation on `integers</api/data_types/integer>`.

## Usage

``` xojo
result = expression1 Xor expression2
```

| Part        | Description                                                                                                                                                                                                                                   |
|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| result      | A `Boolean</api/data_types/boolean>` value if *expression1* and *expression2* are `Boolean</api/data_types/boolean>`; an `Integer</api/data_types/integer>` value if *expression1* and *expression2* are `integers</api/data_types/integer>`. |
| expression1 | Any valid `Boolean</api/data_types/boolean>` or `Integer</api/data_types/integer>` expression. The data types of *expression1* and *expression2* must match.                                                                                  |
| expression2 | Any valid `Boolean</api/data_types/boolean>` or `Integer</api/data_types/integer>` expression. The data types of *expression1* and *expression2* must match.                                                                                  |

## Notes

If you use <span class="title-ref">Xor</span> with two `booleans</api/data_types/boolean>`, it returns the logical <span class="title-ref">Xor</span> of the `booleans</api/data_types/boolean>`. The result table for <span class="title-ref">Xor</span>, `Or</api/language/operators/bitwise_logical/or>`, and `And</api/language/operators/bitwise_logical/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 <span class="title-ref">Xor</span> with two `booleans</api/data_types/boolean>`, it returns `True</api/language/true>` if the `booleans</api/data_types/boolean>` are not equal. The logic is "Not (a=b)". The result is a `boolean</api/data_types/boolean>`.

When you pass two `integers</api/data_types/integer>`, it returns an `integer</api/data_types/integer>` that is the result of comparing each bit of the two `integers</api/data_types/integer>` passed and assigning 1 to the bit position in the `integer</api/data_types/integer>` returned if both bits in the same position in the `integer</api/data_types/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</api/language/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 <span class="title-ref">Xor</span> on the two integers passed.

``` xojo
Var i As Integer
I = 5 Xor 3 ' returns 6
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`And</api/language/operators/bitwise_logical/and>`, `Not</api/language/operators/bitwise_logical/not>`, `Or</api/language/operators/bitwise_logical/or>` operators; `Bitwise</api/language/bitwise>` class; `Operator And</api/language/operators/operator_overloads/operator_and>` function; `Operator precedence</api/language/operators/operator_precedence>`

</div>
