Calculate bitwise XOR operation between two numbers
Calculate bitwise XOR operations between two numbers instantly with our free online XOR calculator. This tool helps programmers, cryptography students, and computer science professionals perform exclusive OR operations with visual bit-by-bit explanations. Simply enter two numbers and see the XOR result in decimal, binary, and hexadecimal formats in real-time.
XOR returns 1 when bits are different, 0 when they are the same.
Bitwise XOR (exclusive OR) calculator compares bits and outputs 1 only when inputs differ. XOR has unique properties: self-inverse, no carry, and useful for toggling, swapping, checksums, and simple encryption.
Input two numbers. Calculator converts to binary and XORs each bit position. Output is 1 if inputs differ (0^1=1, 1^0=1), 0 if same (0^0=0, 1^1=0). Key property: A XOR B XOR B = A.
XOR truth table: 0^0=0, 0^1=1, 1^0=1, 1^1=0. Properties: commutative (A^B = B^A), associative ((A^B)^C = A^(B^C)), self-inverse (A^A=0), identity (A^0=A). Used in: encryption, checksums, swapping, bit toggling.
XOR with key to encrypt, XOR again to decrypt.
plaintext XOR key = cipher, cipher XOR key = plaintextXOR all bytes for simple error detection.
Flip specific bits without conditionals.
value ^ mask toggles masked bitsa ^= b; b ^= a; a ^= b; swaps a and b.
// Basic XOR
console.log(12 ^ 10); // 6
// 1100 (12)
// 1010 (10)
// ----
// 0110 (6)
// Toggle bits
const toggleBit = (n, pos) => n ^ (1 << pos);
toggleBit(0b1010, 1); // 0b1000 (toggle bit 1 off)
toggleBit(0b1000, 1); // 0b1010 (toggle bit 1 on)
// Simple XOR encryption/decryption
const xorEncrypt = (text, key) =>
text.split('').map((c, i) =>
String.fromCharCode(c.charCodeAt(0) ^ key.charCodeAt(i % key.length))
).join('');
const encrypted = xorEncrypt('Hello', 'key');
const decrypted = xorEncrypt(encrypted, 'key'); // "Hello"
// Find unique element (all others appear twice)
const findUnique = arr => arr.reduce((a, b) => a ^ b, 0);
findUnique([1, 2, 1, 3, 2]); // 3XOR outputs 1 when bits differ. Self-inverse property enables encryption, swapping, and finding unique elements.
Use XOR for bit toggling, simple checksums, finding unique elements, and as building block for encryption. Combine with other bitwise ops for complex bit manipulation.
XOR is its own inverse: encrypt(decrypt(x)) = x. Simple XOR cipher: ciphertext = plaintext ^ key, plaintext = ciphertext ^ key. Not secure alone (key reuse is vulnerable) but used in stream ciphers.