XOR Calculator
Calculate the bitwise exclusive OR (XOR) of two numbers.
Result: A XOR B
Enter both values to see the result in decimal, hex, binary, and octal.
XOR truth table
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR Calculator – Bitwise Exclusive OR
Calculate the bitwise XOR of two numbers and see exactly which bits differ. Enter values in decimal, hexadecimal (0x…), binary (0b…), or octal (0o…) and the result appears instantly in all four formats, together with an aligned bit-by-bit view. For example 12 XOR 10 = 6, because 1100 XOR 1010 = 0110.
How XOR works
XOR ("exclusive or") compares two bits and returns 1 when they are different and 0 when they are the same. Applied to whole numbers, the operation is carried out on every bit position independently. In most programming languages it is written with the caret operator: a ^ b.
Useful properties of XOR
a ^ 0 = a– XOR with zero changes nothing.a ^ a = 0– any value XORed with itself is zero.a ^ b ^ b = a– applying the same key twice restores the original, the basis of simple XOR encryption and one-time pads.- XOR is commutative and associative, so the order of operands does not matter.
Where XOR is used
- Toggling bits –
flags ^ maskflips exactly the bits set in the mask. - Checksums and parity – XOR of all bytes gives a simple checksum used in NMEA sentences, RAID 5 parity, and many serial protocols.
- Cryptography – stream ciphers such as ChaCha20 and AES-CTR XOR the keystream with the data.
- Finding differences – XOR two values and every 1 bit marks a difference; count them to get the Hamming distance.
- Interview puzzles – swapping two variables without a temporary variable, or finding the single non-duplicated number in a list.
Bit width and negative numbers
With Auto width the calculator picks the smallest multiple of 8 bits that holds both operands. Choose 8, 16, 32, 64, or 128 bits to work with fixed-size integers; negative inputs are then encoded in two's complement, and the result is shown both unsigned and signed. For other operations see the Bitwise Calculator.
Frequently Asked Questions
What is 5 XOR 3?
6. In binary 101 XOR 011 = 110, because the bits differ in the two highest positions and are equal in the lowest one.
How do I calculate XOR of hex numbers?
Type them with a 0x prefix (e.g. 0xFF and 0x0F) or set the input format to Hexadecimal. The result is shown in hex, decimal, binary, and octal.
Why is XOR used in encryption?
Because XOR with the same key twice returns the original data (a ^ k ^ k = a), and a random key makes every output equally likely. Stream ciphers generate a keystream and XOR it with the message.