XOR Calculator

Calculate bitwise XOR (exclusive OR) of two numbers. Results in decimal, hex, and binary. Includes one-time pad demo, string XOR, parity bits, and Hamming distance.

A XOR B (Decimal)
A XOR B (Hexadecimal)
A XOR B (Binary)
Extended More scenarios, charts & detailed breakdown
XOR Result
Hex
Binary (8-bit)
A AND B
A OR B
Professional Full parameters & maximum detail

XOR Result

A XOR B
Hex
Binary (8-bit)

Applications

Swap Without Temp Variable
Parity Bit of XOR Result
Hamming Distance (A, B)

How to Use This Calculator

  1. Enter Number A and Number B in decimal.
  2. Read the XOR result instantly in decimal, hexadecimal, and 8-bit binary.
  3. Use Two Numbers tab to also see AND, OR alongside XOR for comparison.
  4. Use String XOR tab to see byte-by-byte XOR encryption on "HELLO" with your key.
  5. Use One-Time Pad tab to verify XOR encryption is its own decryption.
  6. Professional tab shows XOR swap, parity bit, and Hamming distance between A and B.

Formula

Bit rule: 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0

Key identities: A⊕A=0, A⊕0=A, (P⊕K)⊕K=P

Example

170 (10101010₂) XOR 85 (01010101₂) = 255 (11111111₂). Hamming distance = 8 (all bits differ).

Frequently Asked Questions

  • XOR, or exclusive OR, is a fundamental bitwise operation that returns 1 when its two input bits differ and 0 when they are the same. The truth table: 0⊕0=0, 0⊕1=1, 1⊕0=1, 1⊕1=0 — hence 'exclusive' because it excludes the case where both are 1. When applied to multi-bit numbers, XOR operates on each bit position independently. For example, 12 (1100₂) XOR 10 (1010₂) = 0110₂ = 6: the first two bit pairs match (both 1, both 1) giving 0,0 and the last two pairs differ (0 vs 1, 0 vs 1) giving 1,1. XOR has elegant mathematical properties: commutative (A⊕B = B⊕A), associative (A⊕(B⊕C) = (A⊕B)⊕C), its own inverse (A⊕A = 0), and identity element (A⊕0 = A). These properties make XOR one of the most versatile operations in computing, appearing in cryptography, error detection, data structures, and low-level bit manipulation.
  • XOR is the cornerstone of stream ciphers and the one-time pad because it is a perfect mixing operation — XOR-ing plaintext P with a key K produces ciphertext C=P⊕K, and XOR-ing ciphertext with the same key perfectly recovers the plaintext: C⊕K = P⊕K⊕K = P. No other single-bit operation has this clean inverse property. Block ciphers like AES use XOR extensively in their AddRoundKey step. Galois Counter Mode (GCM) authentication uses XOR in GF(2⁸) polynomial arithmetic. CRC (Cyclic Redundancy Check) implements polynomial division over GF(2) using XOR as the subtraction operation. RAID-5 storage uses XOR parity: XOR-ing all data strips produces a parity strip that can reconstruct any one lost drive. The security of XOR-based encryption depends entirely on key quality — XOR with a truly random key (one-time pad) is information-theoretically unbreakable; XOR with a repeated or predictable key is trivially broken by frequency analysis.
  • Yes, XOR swap is a genuine algorithm that exchanges two integer values without any temporary variable. The three-step algorithm: A = A⊕B, then B = B⊕A (= B⊕(A⊕B) = A), then A = A⊕B (= (A⊕B)⊕A = B). The variables now hold swapped values. Proof uses XOR properties: commutativity, associativity, and self-inverse (x⊕x=0). It works because after step 1, A temporarily holds A⊕B; step 2 extracts the original A by XOR-ing again; step 3 extracts the original B. There is one critical pitfall: if A and B are the same variable (same memory address), all three steps set it to zero, destroying both values. Modern compilers generate more efficient code using CPU register swaps, so XOR swap offers no practical performance advantage today — but it remains a classic demonstration of XOR properties and a common interview question testing bitwise operation fluency.
  • A one-time pad (OTP) is an encryption scheme proven mathematically unbreakable when used correctly. Each plaintext byte is XOR-ed with a corresponding random key byte. Claude Shannon proved in 1949 that OTP achieves 'perfect secrecy': the ciphertext reveals zero information about the plaintext to anyone lacking the key. No computational power, however vast, can break it. The proof: if the key is uniformly random, every possible plaintext maps to the same ciphertext for some key, making all plaintexts equally likely from the ciphertext alone. However, OTP has severe practical limitations: the key must be truly random (not pseudorandom), exactly as long as the message, transmitted securely to the recipient (often harder than sending the message itself), and never reused. Key reuse is fatal — XOR-ing two ciphertexts encrypted with the same key yields their plaintext XOR, which can be decrypted via frequency analysis. The Soviet VENONA codes were broken in the 1940s precisely because of OTP key reuse.
  • XOR is the foundation of parity-based error detection. A parity bit is computed as XOR of all bits in a data word: even parity means XOR = 0, odd parity means XOR = 1. The receiver recalculates parity — any single-bit error flips the parity, immediately revealing corruption. This is used in UART serial communication and RAM with ECC. Hamming codes extend this idea: multiple strategically placed parity bits (at positions 1, 2, 4, 8, ...) each cover different subsets of data bits via XOR, enabling single-bit error correction and double-bit error detection (SECDED codes used in ECC memory). CRC (Cyclic Redundancy Check) is a more powerful extension using polynomial division over GF(2) with XOR as subtraction — CRC-32 can detect all burst errors ≤ 32 bits long. RAID-5 storage uses XOR parity across drives: XOR of all data strips stored on a dedicated parity drive allows full reconstruction of any single failed drive, providing redundancy with only 1/N storage overhead.

Related Calculators

Sources & References (5)
  1. NIST FIPS 180-4 — Secure Hash Standard (XOR in SHA round functions) — NIST
  2. Bruce Schneier — Applied Cryptography (XOR & Stream Ciphers) — Wiley
  3. Hacker's Delight — Henry S. Warren Jr. — Addison-Wesley
  4. MIT OCW 6.004 — Computation Structures (Digital Logic & Boolean Algebra) — MIT OpenCourseWare
  5. RFC 4493 — AES-CMAC Algorithm (XOR in message authentication) — IETF