XOR Calculator

Compute bitwise XOR of two binary numbers instantly

0 bits
0 bits

Try an example:

Enter two binary numbers and click Calculate XOR to see the bit-by-bit breakdown.

Tip: XOR (exclusive OR) returns 1 when the two input bits are different, and 0 when they are the same. The result is also shown in hexadecimal.

How XOR Works

XOR stands for "exclusive OR." It's a logical operation that outputs true (1) only when the two inputs are different. If both inputs are the same — both 0 or both 1 — the output is false (0). The easiest way to remember XOR is: "one or the other but not both."

Mathematically, XOR is written as A ⊕ B. The truth table has only four rows, and once you memorize it, you can XOR any two binary numbers in your head for short sequences:

  • 0 ⊕ 0 = 0 — same bits, result is 0
  • 0 ⊕ 1 = 1 — different bits, result is 1
  • 1 ⊕ 0 = 1 — different bits, result is 1
  • 1 ⊕ 1 = 0 — same bits, result is 0

Practical Uses of XOR

XOR shows up everywhere in computing because of one key property: it's reversible. If you XOR a value twice with the same key, you get back the original. This makes XOR the foundation of several important techniques:

Encryption (XOR Cipher)

XOR is the building block of many encryption algorithms. A simple XOR cipher works by XORing plaintext bytes with a key. To decrypt, you XOR the ciphertext with the same key. While a single XOR cipher is easy to break with frequency analysis, modern ciphers like AES use XOR internally as one of their core operations alongside substitution and permutation.

Error Detection (Parity Bits)

XOR is used to generate parity bits in error detection. XORing all the bits of a data word tells you whether the number of 1s is odd or even. RAID arrays use XOR parity to reconstruct data when a drive fails — they XOR all the remaining drives to recover the missing one.

Graphics (Bitmap Operations)

In computer graphics, XOR is often used for drawing cursors and selection boxes. XORing pixels with the background is fast and reversible — drawing the same shape again in the same location erases it and restores the original pixels underneath.

Swap Values Without a Temp Variable

There's a classic trick that uses XOR to swap two variables without needing a third temporary variable. In C: a ^= b; b ^= a; a ^= b;. After those three XOR operations, the values of a and b are swapped. It works because of XOR's reversibility property.

XOR Truth Table Reference

Input A Input B A ⊕ B
000
011
101
110

This is the complete XOR truth table. Memorize these four rows and you can XOR any two binary values.

XOR in Programming

Most programming languages use the ^ operator for bitwise XOR. Here's how it looks in common languages:

  • C / C++: int result = a ^ b;
  • Java: int result = a ^ b;
  • Python: result = a ^ b
  • JavaScript: let result = a ^ b;
  • C#: int result = a ^ b;
  • Go: result := a ^ b
  • Rust: let result = a ^ b;
  • Ruby: result = a ^ b

In every case, ^ performs a bitwise XOR — it compares the two values bit by bit and produces a result where each bit follows the XOR truth table.

Related Tools

Bit Shift Calculator → Binary Calculator → Binary Logic Gates → XOR Encryption → Binary Adder Circuit →