XOR Calculator
Perform a bitwise XOR (exclusive OR) operation on two numbers. Enter values in decimal, binary, or hexadecimal and see the result in all three formats. Essential for programming, cryptography, and digital logic.
XOR (exclusive OR) is a bitwise operation that compares two bits and returns 1 only when the bits are different. If both bits are the same (both 0 or both 1), the result is 0.
XOR Truth Table:
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
How Bitwise XOR Works:
To XOR two numbers, convert them to binary and compare each pair of bits. For example, 12 XOR 10: 1100 XOR 1010 = 0110 (which is 6 in decimal).
Key Properties of XOR:
- Self-inverse: A XOR A = 0 (any number XOR itself is zero)
- Identity: A XOR 0 = A (XOR with zero returns the original)
- Commutative: A XOR B = B XOR A
- Associative: (A XOR B) XOR C = A XOR (B XOR C)
Common Uses:
- Swapping variables without temp: a = a ^ b; b = a ^ b; a = a ^ b;
- Encryption: XOR is a building block in many ciphers
- Checksums and error detection: XOR parity checks
- Bit toggling: XOR with a mask to flip specific bits
- Finding the unique element: XOR all elements in a list where every element appears twice except one