XOR Calculator

Enter two whole numbers to compute their bitwise XOR (exclusive OR), shown in decimal, binary, and hexadecimal.

Quick Facts

XOR rule
1 if bits differ, 0 if bits match
0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0.
Identity properties
A⊕0 = A and A⊕A = 0
XOR-ing a value with itself always cancels to zero.
Commutative & associative
A⊕B = B⊕A
Order does not matter, which is why XOR is used in swap tricks and checksums.

Your Results

Calculated
A XOR B (decimal)
-
Result of the bitwise exclusive OR
Binary result
-
Padded to the selected bit width
Hexadecimal result
-
Base-16 representation
Differing bits
-
Hamming distance between A and B

Ready

Enter two non-negative whole numbers and a bit width, then press Calculate.

How XOR (Exclusive OR) Works

XOR, short for "exclusive OR," is one of the four basic bitwise logic operations (alongside AND, OR, and NOT). It compares two numbers one binary digit at a time and outputs a 1 wherever the two bits are different, and a 0 wherever they are the same. This calculator converts your two decimal inputs to binary, XORs them bit by bit, and shows the result in decimal, binary, and hexadecimal, along with how many bit positions differ between the two inputs.

The XOR truth table and formula

For a single pair of bits, XOR follows this table: 0⊕0 = 0, 0⊕1 = 1, 1⊕0 = 1, 1⊕1 = 0. To XOR two full numbers, write both in binary with the same number of digits (pad with leading zeros), line them up by place value, and apply the truth table to each column independently — there is no carrying between columns, unlike addition. For example, 12 XOR 10 in 8-bit binary: 00001100 ⊕ 00001010 = 00000110, which is 6 in decimal. Algebraically, XOR is equivalent to addition modulo 2 in each bit position, and it can also be expressed as (A OR B) AND NOT (A AND B) — true wherever at least one input is true but not both.

Bit width and range

Because computers store numbers using a fixed number of bits, this calculator lets you choose a bit width (4, 8, 16, or 32 bits) that determines the padding of the binary output and the maximum value each input can hold (2width − 1). Choosing a width that is too small for your numbers will trigger a validation error; choosing a wider one than necessary is always safe and simply adds leading zeros.

Common sources of error

  • Confusing XOR with OR: OR returns 1 when either or both bits are 1; XOR returns 1 only when the bits are different, so 1⊕1 = 0 while 1 OR 1 = 1.
  • Forgetting to pad with zeros: when comparing binary numbers of different lengths by hand, misaligning the columns gives the wrong answer — always pad the shorter number with leading zeros first.
  • Using negative numbers: this calculator works with non-negative integers; negative numbers require a defined bit width and two's-complement convention to XOR correctly.

Real-world applications

  • Error detection: parity bits and checksums (like CRC) use repeated XOR operations to detect single-bit transmission errors.
  • Simple encryption: XOR ciphers and one-time pads encrypt data by XOR-ing it with a key, and decrypt it by XOR-ing again with the same key, since A⊕B⊕B = A.
  • Swapping variables: the classic "XOR swap" exchanges two variables without a temporary storage variable: a = a⊕b; b = a⊕b; a = a⊕b.
  • Toggling bits and graphics: XOR is used to flip specific bits (a flag register, a pixel mask) while leaving all other bits unchanged.

Frequently Asked Questions

What does XOR mean?
XOR (exclusive OR) is a bitwise operation that compares two numbers bit by bit. Each output bit is 1 if the corresponding input bits are different, and 0 if they are the same: 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0.
How do you calculate XOR by hand?
Write both numbers in binary, aligned by place value, then compare each column: write 1 if the two bits differ and 0 if they match. For example, 12 (1100) XOR 10 (1010) gives 0110, which is 6 in decimal.
What is XOR used for in real life?
XOR is used for parity and error-checking bits, simple stream ciphers and one-time-pad style encryption, checksums like CRC, and the classic swap-two-variables-without-a-temp trick (a=a⊕b; b=a⊕b; a=a⊕b).
How is XOR different from OR?
OR returns 1 if at least one input bit is 1 (including when both are 1), while XOR returns 1 only when the bits differ — so 1 OR 1 = 1, but 1 XOR 1 = 0. XOR is sometimes called "exclusive OR" for this reason.