> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bitwise.xor

> Performs a bitwise XOR operation on two integers, returning 1 for each bit position where the operands differ.

## Description

Performs a bitwise XOR (exclusive OR) operation on two integers. Each bit in the result is 1 if the corresponding bits in the operands are different.

## Syntax

```cypher theme={null}
flex.bitwise.xor(a, b)
```

## Parameters

| Parameter | Type             | Required | Description    |
| --------- | ---------------- | -------- | -------------- |
| `a`       | number (integer) | Yes      | First operand  |
| `b`       | number (integer) | Yes      | Second operand |

## Returns

**Type:** number (integer)

The result of the bitwise XOR operation.

## Examples

### Example 1: Basic XOR Operation

```cypher theme={null}
RETURN flex.bitwise.xor(12, 10) AS result
```

**Output:**

```text theme={null}
result
------
6
```

(Binary: 1100 XOR 1010 = 0110 = 6)

### Example 2: Toggling Bits

```cypher theme={null}
WITH 5 AS value, 3 AS toggleMask
RETURN flex.bitwise.xor(value, toggleMask) AS toggled
```

**Output:**

```text theme={null}
toggled
-------
6
```

(Binary: 0101 XOR 0011 = 0110)

### Example 3: Simple Encryption/Decryption

```cypher theme={null}
WITH 42 AS data, 17 AS key
WITH flex.bitwise.xor(data, key) AS encrypted
RETURN flex.bitwise.xor(encrypted, key) AS decrypted
```

**Output:**

```text theme={null}
decrypted
---------
42
```

(XOR with same key twice returns original value)

## Notes

* Operates on 32-bit signed integers in JavaScript
* Both operands are converted to integers if needed
* XOR with same value twice returns the original value
* Commonly used for toggling flags and simple encryption

## See Also

* [bitwise.and](/udfs/flex/bitwise/and) - Bitwise AND operation
* [bitwise.or](/udfs/flex/bitwise/or) - Bitwise OR operation
* [bitwise.not](/udfs/flex/bitwise/not) - Bitwise NOT operation

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What does flex.bitwise.xor return?">
    It returns an integer where each bit is 1 only if the corresponding bits in the two operands differ. For example, `flex.bitwise.xor(5, 3)` returns `6`.
  </Accordion>

  <Accordion title="What is XOR commonly used for?">
    XOR is useful for toggling flags, simple checksums, and detecting differences between two bitmasks.
  </Accordion>
</AccordionGroup>
