# XOR Calculator

Perform bitwise XOR on two numbers in decimal, binary, or hex. See results in all three formats. Free online XOR calculator for programmers.

## What this calculates

Perform a bitwise XOR (exclusive OR) operation on two numbers. Enter values in decimal, binary, or hexadecimal and see the result in all three formats. Essential for programming, cryptography, and digital logic.

## Inputs

- **Input Format** — options: Decimal, Binary, Hexadecimal — The number format for your input values.
- **Value A** — The first operand for the XOR operation.
- **Value B** — The second operand for the XOR operation.

## Outputs

- **Result (Decimal)** — formatted as text — The XOR result in decimal.
- **Result (Binary)** — formatted as text — The XOR result in binary.
- **Result (Hexadecimal)** — formatted as text — The XOR result in hexadecimal.
- **Value A (Binary)** — formatted as text — First operand in binary for visualization.
- **Value B (Binary)** — formatted as text — Second operand in binary for visualization.

## Details

XOR (exclusive OR) is a bitwise operation that compares two bits and returns 1 only when the bits are different. If both bits are the same (both 0 or both 1), the result is 0.

**XOR Truth Table:**

| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

**How Bitwise XOR Works:**

To XOR two numbers, convert them to binary and compare each pair of bits. For example, 12 XOR 10: 1100 XOR 1010 = 0110 (which is 6 in decimal).

**Key Properties of XOR:**

- **Self-inverse:** A XOR A = 0 (any number XOR itself is zero)
- **Identity:** A XOR 0 = A (XOR with zero returns the original)
- **Commutative:** A XOR B = B XOR A
- **Associative:** (A XOR B) XOR C = A XOR (B XOR C)

**Common Uses:**

- **Swapping variables without temp:** a = a ^ b; b = a ^ b; a = a ^ b;
- **Encryption:** XOR is a building block in many ciphers
- **Checksums and error detection:** XOR parity checks
- **Bit toggling:** XOR with a mask to flip specific bits
- **Finding the unique element:** XOR all elements in a list where every element appears twice except one

## Frequently Asked Questions

**Q: What does XOR do?**

A: XOR (exclusive OR) compares two bits and outputs 1 when the bits are different, 0 when they are the same. For multi-bit numbers, it performs this comparison on each pair of corresponding bits. For example, 5 (101) XOR 3 (011) = 6 (110).

**Q: Why is XOR useful in programming?**

A: XOR has several unique properties that make it valuable. You can swap two variables without a temporary variable, toggle specific bits in a bitmask, and find a unique element in an array where all other elements appear twice. Many encryption algorithms also rely heavily on XOR.

**Q: What happens when you XOR a number with itself?**

A: Any number XOR itself equals zero. This is because every bit matches, and XOR outputs 0 for matching bits. This property is used in algorithms: if you XOR all elements of an array where every number appears twice except one, the duplicates cancel out and you are left with the unique number.

**Q: How is XOR used in encryption?**

A: XOR is used in stream ciphers and one-time pads. To encrypt, XOR the plaintext with a key. To decrypt, XOR the ciphertext with the same key (because XOR is its own inverse). While a simple XOR cipher is not secure alone, it is a fundamental building block in strong encryption standards like AES.

---

Source: https://vastcalc.com/calculators/math/xor
Category: Math
Last updated: 2026-04-08
