StringMash.com

XOR calculator

Exclusive OR, bit by bit, with the bits lined up in the working.

13 characters
Updates as you type
Binary0110
Hex6
Decimal6

Show the steps
  1. Line the bits up. XOR gives 1 where the bits differ.
  2. 1100
  3. XOR 1010
  4. = 0110

Using the calculator

Type two numbers with XOR between them: `1100 XOR 1010`, or `1100 ^ 1010`. Set Numbers are in to hex or decimal to XOR those instead, as in `F0 XOR FF` or `12 XOR 10`. The answer comes back in all three, and the working lines up the bits of both numbers and the result.

XNOR, AND, OR, NAND, NOR and NOT work the same way. For AND and OR there's also a bitwise calculator page.

What XOR does

Exclusive OR compares two bits and gives 1 if they're different and 0 if they're the same. 0 XOR 0 is 0, 0 XOR 1 is 1, 1 XOR 0 is 1 and 1 XOR 1 is 0. For longer numbers, it's done for each pair of bits separately, with no carries, so `1100 XOR 1010` is 0110.

Two properties make it useful. XOR with 1 flips a bit and XOR with 0 leaves it alone, so XORing with a mask flips exactly the bits you choose. And XOR undoes itself: A XOR B XOR B is A again. That's the basis of parity checks, RAID 5's recovery of a lost disk, and the oldest machine cipher there is.

Vernam's teleprinter cipher

In 1917 Gilbert Vernam, an engineer at AT&T, found a way to encrypt teleprinter messages automatically. Each character of the message, in five-bit Baudot code, was combined with a character from a key on paper tape using exactly this operation, built from relays. At the far end the same key tape XORed it back. His patent, US 1,310,719, was granted in 1919. With a key that's truly random, never reused and as long as the message, the scheme became the one-time pad, which is unbreakable in principle.

Questions

What is 1 XOR 1?

0. XOR gives 1 only when the two bits are different.

How do I XOR two hex numbers?

Set Numbers are in to hex and type something like F0 XOR FF. The answer is 0F.

Why is XOR reversible?

Because anything XORed with itself is 0, and XORing with 0 changes nothing. So (A XOR B) XOR B gives back A.

What's XNOR?

The opposite of XOR: 1 where the bits match. The calculator flips the result over the width of the longer number, rounded up to whole hex digits.

Sources

Added . What's new