---
title: 3.16 Bitwise XOR Operator (^)
description: "The bitwise XOR (exclusive OR) operator (`^`) performs a logical exclusive OR operation on each corresponding bit of two integral operands. A result bit is set to `1` when the corresponding bits are different. If both bits are the same,…"
url: "https://edcret.in/docs/cpp-programming/operators-cplusplus/3-16-bitwise-xor-operator/"
updated: "2026-07-28"
category: C++ Programming / Operators
---

# 3.16 Bitwise XOR Operator (^)

The bitwise XOR (exclusive OR) operator (`^`) performs a logical exclusive OR operation on each corresponding bit of two integral operands. A result bit is set to `1` when the corresponding bits are different. If both bits are the same, the result bit is `0`.

Bitwise XOR is commonly used for toggling bits, simple encryption techniques, parity calculations, and detecting differences between binary values.

## Source Code

```
#include <iostream>

int main()
{
    int num1 = 12;
    int num2 = 10;

    int result = num1 ^ num2;

    std::cout << "First Number : " << num1 << '\n';
    std::cout << "Second Number: " << num2 << '\n';
    std::cout << "Result       : " << result << '\n';

    return 0;
}
```

## Output

```
First Number : 12
Second Number: 10
Result       : 6
```

## Explanation

- The bitwise XOR operator (`^`) compares the corresponding bits of two integral operands.
- A result bit is set to `1` when the corresponding operand bits are different.
- A result bit is set to `0` when both corresponding operand bits are the same.
- The operands `12` and `10` have the following binary representations:`12 = 1100₂ 10 = 1010₂ -------------- ^ = 0110₂`
- The binary result `0110₂` is equal to the decimal value `6`.
- Bitwise XOR operations are commonly used to toggle bits, compare binary values, and perform parity calculations.
- The bitwise XOR operator is applicable only to integral data types.
- `return 0;` terminates the program successfully.
