🔢 XOR Calculator

Perform bitwise XOR (exclusive OR) operations on binary numbers

How to Use This Calculator

1

Enter Binary Numbers

Input two binary numbers in the input fields. The calculator accepts only 0s and 1s. Examples: 1010, 1100, 1111. XOR (exclusive OR) returns 1 only when the bits are different, and 0 when they're the same.

2

Click Calculate XOR

Press the "Calculate XOR" button to perform the bitwise XOR operation. XOR is exclusive - it returns 1 only when exactly one of the bits is 1, not when both are 1.

3

Review Results

The result shows both the binary XOR result and the decimal equivalent. XOR is useful for toggling bits, finding differences, swapping values, and simple encryption.

Formula

XOR(A, B) = A ^ B

Bitwise XOR: Result bit is 1 only if input bits are different

How it works:

The XOR operation compares each bit position of two binary numbers. If the bits are different (one is 0, the other is 1), the result is 1. If the bits are the same (both 0 or both 1), the result is 0. XOR is "exclusive" because it excludes the case where both are 1.

XOR Truth Table:

ABA XOR B
000
011
101
110

XOR Properties:

  • A XOR A = 0 (same values cancel out)
  • A XOR 0 = A (XOR with 0 is identity)
  • A XOR B = B XOR A (commutative)
  • (A XOR B) XOR C = A XOR (B XOR C) (associative)
  • A XOR B XOR B = A (XOR is its own inverse)

Example 1: 1010 XOR 1100

  • Position 0: 0 XOR 0 = 0
  • Position 1: 1 XOR 0 = 1
  • Position 2: 0 XOR 1 = 1
  • Position 3: 1 XOR 1 = 0
  • Result: 0110 (binary) = 6 (decimal)

Example 2: 1111 XOR 1010

  • Position 0: 1 XOR 0 = 1
  • Position 1: 1 XOR 1 = 0
  • Position 2: 1 XOR 0 = 1
  • Position 3: 1 XOR 1 = 0
  • Result: 0101 (binary) = 5 (decimal)

Example 3: 1010 XOR 1010 (same number)

  • All positions: 1 XOR 1 = 0, 0 XOR 0 = 0
  • Result: 0000 (binary) = 0 (decimal)
  • This demonstrates: A XOR A = 0

Frequently Asked Questions

What is a bitwise XOR operation?

XOR (exclusive OR) is a logical operation that returns 1 only when the input bits are different (one is 0, the other is 1). If both bits are the same (both 0 or both 1), it returns 0. XOR is "exclusive" because it excludes the case where both inputs are 1, unlike regular OR which returns 1 when either or both are 1.

What's the difference between XOR and OR?

OR returns 1 if either or both bits are 1. XOR returns 1 only if exactly one bit is 1 (they're different). For example: 1 OR 1 = 1, but 1 XOR 1 = 0. XOR is "exclusive" - it excludes the case where both are 1.

Why is XOR useful for swapping values?

XOR can swap two values without a temporary variable: a = a XOR b; b = a XOR b; a = a XOR b. This works because XOR is its own inverse: (a XOR b) XOR b = a. This property is useful in low-level programming and optimization.

How is XOR used in encryption?

XOR is used in simple encryption schemes: ciphertext = plaintext XOR key, and decryption: plaintext = ciphertext XOR key. This works because XOR is its own inverse. While XOR alone isn't secure for modern encryption, it's a fundamental building block in more complex cryptographic algorithms.

What does "XOR is its own inverse" mean?

It means that if you XOR a value twice with the same number, you get back the original: (A XOR B) XOR B = A. This is why XOR is useful for toggling bits, swapping values, and encryption. The property A XOR A = 0 is also a consequence of this.

Can I use XOR with decimal numbers?

Yes, but the calculator converts decimal numbers to binary first. The XOR operation is performed bitwise, then converted back to decimal. Enter your decimal numbers, and the calculator will show both binary and decimal representations of the XOR result.