Binary XOR

Calculate bitwise Exclusive OR (XOR) for binary strings. Free online Binary XOR Calculator for cryptography and logic operations.

String 1

String 2

Output

Result

What is Binary XOR?

The Binary XOR (Exclusive OR) operation is a critical logic function used in digital electronics and computer science. Unlike the standard OR operation, which returns true if at least one input is true, XOR returns true (1) only when the inputs are different.

If the compared bits are the same (both 0 or both 1), the result is 0. This unique property makes XOR extremely useful for encryption, error detection, and data recovery.

How Binary XOR Works

The operation compares two bits at a time. It is often summarized by the phrase: "One or the other, but not both."

Truth Table

Input AInput BResult (A XOR B)
000
011
101
110

Calculation Example

Let's perform a Binary XOR on two 8-bit numbers: 10101100 and 01101010.

  1. Align the numbers.
  2. If bits differ, write 1. If they are the same, write 0.
  10101100  (Operand 1)
^ 01101010  (Operand 2)
----------
  11000110  (Result)

In this example, the result is 1 wherever the bits in the two operands are different.

Common Applications

XOR is arguably the most versatile bitwise operator, with applications ranging from simple algorithms to complex data storage systems.

1. Cryptography (One-Time Pad)

XOR is the foundation of many encryption algorithms. If you XOR a message with a secret key, you get an encrypted text. XORing that encrypted text with the key again retrieves the original message.

  • Message ^ Key = Ciphertext
  • Ciphertext ^ Key = Message

2. RAID 5 Data Recovery

In RAID storage systems, XOR is used to calculate parity. If one drive fails, the missing data can be perfectly reconstructed by XORing the remaining data blocks.

  • A ^ B = Parity
  • If A is lost: Parity ^ B = A

3. Error Detection (Checksums)

Network protocols use XOR (often as part of a Cyclic Redundancy Check or CRC) to verify that data has not been corrupted during transmission.

4. Swapping Variables

You can swap the values of two variables without using a temporary storage variable using XOR:

  1. x = x ^ y
  2. y = x ^ y
  3. x = x ^ y

Frequently Asked Questions

What does "XOR" stand for?

XOR stands for Exclusive OR. It is called "exclusive" because it excludes the case where both inputs are true (1).

Is XOR reversible?

Yes, XOR is fully reversible. This is why it is used in cryptography and data recovery. If you know the result and one of the operands, you can always recover the other operand.

Can I use this calculator for text?

Yes, this calculator allows you to input text strings. It converts the characters to their binary ASCII/Unicode representation, performs the XOR operation, and displays the result. This is essentially how simple XOR encryption works.

Why is XOR used in checksums?

XOR is computationally fast and effectively detects single-bit errors. While more complex methods (like CRC32) are used for robust error checking, simple XOR checksums are efficient for basic verification.

References

  1. MDN Web Docs. "Bitwise XOR (^)". Mozilla Developer Network. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR
  2. GeeksforGeeks. "Bitwise Operators in C/C++". GeeksforGeeks. https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/