Perform bitwise exclusive OR (XOR) on two numbers. Supports binary (bin), decimal (dec), and hexadecimal (hex) input formats.
The exclusive OR (XOR, ⊕) is a fundamental logical operation that outputs true (1) exactly when the inputs differ. In digital electronics and computer arithmetic, XOR appears everywhere: from binary addition without carry to error detection, cryptography, and graphics blending.
| A | B | A ⊕ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
From hardware design to high-level algorithms, XOR stands out because of its reversible nature and perfect balance. Here are key domains:
a ^= b; b ^= a; a ^= b; exchanges values without temporary variable.
reg ^= mask flips bits where mask has 1's.
In RAID storage systems, XOR parity is used to reconstruct lost data. For a stripe of disks, the parity block P = D1 ⊕ D2 ⊕ ... ⊕ Dn. If any single disk fails, the missing data can be recovered by XORing the remaining disks with the parity block. This illustrates the powerful self-inverse property: D1 = P ⊕ D2 ⊕ D3 ... . Our calculator demonstrates exactly the bitwise XOR operation that makes such redundancy possible.
Let’s compute 42 ⊕ 13 (decimal). Binary: 42 = 101010, 13 = 001101 (aligned to 6 bits). XOR per bit: 1⊕0=1, 0⊕0=0, 1⊕1=0, 0⊕1=1, 1⊕0=1, 0⊕1=1 → result = 100111 which equals decimal 39. Our calculator automatically handles alignment and variable bit lengths.
| Operation | Binary Example | Result | Application |
|---|---|---|---|
| XOR with 0 | 1101 ⊕ 0000 | 1101 | Identity preservation |
| XOR with all 1's | 1010 ⊕ 1111 | 0101 | Bitwise NOT (toggle all bits) |
| XOR swap | x=5 (0101), y=3 (0011) → x=x⊕y; then y=x⊕y; then x=x⊕y → (3,5) | Swapped | No temporary variable swap |
| Parity generation | 101 (bits) → 1⊕0⊕1 = 0 (even parity) | Parity bit | Checksum for simple error detection |
XOR gates are built from AND-OR-Invert structures. In modern microprocessors, the XOR operation executes in a single clock cycle, making it ideal for high-speed checksums. Programmers leverage XOR in hash functions and randomness extraction (e.g., Linear Feedback Shift Registers). The expression H(x) = x ⊕ (x >> 16) appears in many mixing functions.