Skip to content
Math

XOR Calculator

Enter two integers in any base (binary, decimal, hexadecimal, or octal), choose a word size, and instantly get the bitwise XOR result in all four bases. The step-by-step panel shows every bit aligned side by side so you can follow the logic exactly, and the insight panel explains what the result means in plain language.

Your details

The base used for both inputs. Results are always shown in all four bases.
Enter an integer in the selected base. Prefix 0b, 0x, or 0o is optional.
Enter an integer in the selected base.
The number of bits used for the operation. Results are masked to this width. 8-bit is suitable for most educational examples.
XOR result (decimal)
49

The bitwise XOR result as a base-10 integer

XOR result (binary)0011 0001
XOR result (hex)31
XOR result (octal)61
Set bits in result3
A (decimal)60
B (decimal)13
A60
B13
A XOR B49

A XOR B = 49 (binary: 0011 0001, hex: 31)

  • 3 out of 8 bits differ between A and B. Each differing bit position becomes a 1 in the result.
  • XOR is self-inverse: XORing any value with itself gives 0, and XORing with 0 leaves it unchanged. So (A XOR B) XOR B = A (49 XOR 13 XOR 13 = 60).
  • In one-time-pad encryption, a plaintext byte (60) XORed with a key byte (13) produces ciphertext (49). XORing the ciphertext with the same key recovers the original.

Next stepTo recover A from the XOR result, XOR it again with B: 49 XOR 13 = 60.

What is bitwise XOR?

Exclusive OR (XOR) is a fundamental bitwise operation that compares two binary numbers one bit at a time. For each pair of bits in the same position, XOR outputs 1 if the two bits are different and 0 if they are the same. The operation is written as A XOR B, A ^ B (in most programming languages), or A + B (mod 2) in boolean algebra. Unlike ordinary OR, XOR excludes the case where both inputs are 1, which is why it is called exclusive. Applying XOR to two 8-bit numbers, for example, processes all eight bit pairs simultaneously, producing an 8-bit result where each output bit tells you whether the corresponding pair of input bits differed.

How this calculator works

Enter any two non-negative integers in the Input base field (decimal, binary, hexadecimal, or octal). The Word size setting controls how many bits are used for the operation: 4-bit for nibbles, 8-bit for bytes, 16-bit for words, and 32-bit for double words. Inputs are masked to the chosen width, so any bits above the limit are discarded. The result appears simultaneously in decimal, binary (padded and grouped into nibbles), hexadecimal, and octal, and the step-by-step panel walks through the full bit-level alignment. The set-bit count (popcount or Hamming weight) tells you how many bit positions differ between A and B, which is equivalent to the Hamming distance between the two values.

Key mathematical properties of XOR

XOR obeys several algebraic laws that make it useful in practice. It is commutative (A XOR B = B XOR A) and associative ((A XOR B) XOR C = A XOR (B XOR C)), so the order of operands does not matter. Any value XORed with itself gives 0 (A XOR A = 0), and any value XORed with 0 is unchanged (A XOR 0 = A). Together these properties give the self-inverse law: (A XOR B) XOR B = A, which means XOR is its own inverse. This makes it trivial to undo, which is why it appears in cryptography and error correction. XOR is also related to addition without carry in binary: 1 XOR 1 = 0 with no carry, just as 1 + 1 = 10 in binary but the carry is dropped. The number of 1-bits in the XOR result is the Hamming distance between A and B, a measure used in coding theory to quantify how different two bit strings are.

Real-world applications of XOR

XOR appears in an astonishing range of practical applications. In cryptography, one-time-pad encryption XORs plaintext with a random key of the same length to produce ciphertext, and applying the same key again recovers the original. Stream ciphers like RC4 and modern authenticated encryption schemes use XOR at their core. In error detection and correction, XOR is used to compute parity bits and CRC checksums that can detect or correct transmission errors. RAID-5 storage systems use XOR across drive stripes to enable recovery from a single disk failure. In computer hardware, half-adder and full-adder circuits are built from XOR and AND gates, making XOR the basis of binary arithmetic. Programmers also use XOR to toggle individual bits in a register or flag field without touching other bits, and the classic XOR swap trick exchanges two variables without a temporary. In data structures, XOR-linked lists encode both the previous and next pointer in a single field.

XOR truth table

A (input bit)B (input bit)A XOR B (output bit)Meaning
00 0 Both 0 - no difference
01 1 Bits differ - output 1
10 1 Bits differ - output 1
11 0 Both 1 - no difference

XOR outputs 1 (true) when the two input bits differ and 0 (false) when they are the same. It is equivalent to addition modulo 2.

Frequently asked questions

What does XOR mean?

XOR stands for exclusive OR. Like ordinary OR, it returns true (1) when at least one input is true. But unlike OR, it returns false (0) when both inputs are true. It is "exclusive" because it excludes the case where both are 1. Bit-by-bit: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0.

How do I calculate XOR by hand?

Convert both numbers to binary. Align them so the least significant bits are on the right. Then compare each column: write 1 if the two bits differ and 0 if they are the same. Convert the resulting binary number back to the base you need. For example, 12 (1100 in binary) XOR 10 (1010) is 0110, which is 6 in decimal.

What is XOR used for in programming?

XOR has many practical uses: toggling specific bits in a flag variable (without changing others), generating checksums and parity bits, simple encryption (XOR cipher), swapping two integers without a temporary variable (a ^= b; b ^= a; a ^= b;), detecting which element appears an odd number of times in an array (XOR of an even number of identical values cancels to 0), and computing Hamming distances between bit strings.

What is the difference between XOR and OR?

Ordinary OR (inclusive OR) outputs 1 when at least one input bit is 1, including the case where both are 1. XOR (exclusive OR) also outputs 1 when the bits differ, but it outputs 0 when both bits are 1. In other words, OR is 1 in three of the four input combinations, while XOR is 1 in only two (0,1 and 1,0). In symbols: 1 OR 1 = 1, but 1 XOR 1 = 0.

Why does XOR of a number with itself equal zero?

Because XOR outputs 1 only when two bits differ. If you XOR a number with itself, every bit in the same position is identical, so every output bit is 0. This makes XOR a useful way to clear a value or to test whether two values are equal (if A XOR B = 0, then A = B).

What is the XOR of three or more numbers?

XOR is associative, so you can chain it left to right: compute A XOR B first, then XOR that result with C, and so on. For example, 5 XOR 3 XOR 6 = (5 XOR 3) XOR 6 = 6 XOR 6 = 0. The result is the same regardless of the order or grouping, because XOR is both commutative and associative.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…