How to use the XOR calculator
- XOR numbers: enter two or more values, one per line. Prefix hex with
0x, binary with0band octal with0o, or choose a base. Underscores and spaces in long numbers are ignored. - Read the result in hex, decimal, binary and octal. The dark panel lines up every input bit by bit so you can see which columns differ.
- XOR text or bytes: combine a message with a key (text or hex), byte by byte with the key repeating. Press Use result as data to run it again and get the original back.
- XOR checksum: paste a frame of hex bytes to get its Block Check Character, with options to skip the first (STX) or last byte.
XOR truth table
| A | B | A XOR B | Meaning |
|---|---|---|---|
| 0 | 0 | 0 | Same: 0 |
| 0 | 1 | 1 | Different: 1 |
| 1 | 0 | 1 | Different: 1 |
| 1 | 1 | 0 | Same: 0 |
XOR (exclusive OR, written ^ in C, Java, JavaScript and Python, and ⊕ in maths) is 1 when an odd number of its inputs are 1. That generalises to many inputs: XOR of a list is the parity of each bit column. Compared with the other gates: AND needs both bits set, OR needs at least one, and XNOR is the inverse of XOR (1 when bits are equal). Try them on the bitwise calculator.
Worked examples
| Inputs | Binary | Result |
|---|---|---|
| 12 XOR 10 | 1100 ⊕ 1010 | 0110 = 6 |
| 0xF0 XOR 0x3C | 1111 0000 ⊕ 0011 1100 | 1100 1100 = 0xCC |
| 0xF0 XOR 0x3C XOR 0xAA | 1100 1100 ⊕ 1010 1010 | 0110 0110 = 0x66 |
| ‘a’ XOR 0x20 | 0110 0001 ⊕ 0010 0000 | 0100 0001 = ‘A’ (case flip) |
| 0xFF XOR x | flips all 8 bits | bitwise NOT of a byte |
| BCC of 31 32 33 03 | 0x31 ⊕ 0x32 ⊕ 0x33 ⊕ 0x03 | 0x33 |
Properties that make XOR useful
- Self-inverse:
a ^ a = 0anda ^ 0 = a, soa ^ k ^ k = a. That is the whole basis of XOR ciphers, RAID parity and the classic swap tricka ^= b; b ^= a; a ^= b. - Commutative and associative: order and grouping do not matter, which is why you can XOR a whole list in any order.
- Toggling bits:
flags ^ maskflips exactly the bits set in the mask, leaving the rest alone. - Finding differences:
a ^ bhas a 1 wherever two values differ; counting those bits gives the Hamming distance. - Finding the odd one out: XOR every item of a list where all values appear twice except one; the result is the unpaired value.
XOR checksums (BCC / LRC)
Many serial and embedded protocols append a one-byte Block Check Character: the XOR of the message bytes. Examples include smart-card (ISO 7816) T=1 frames, many RS-232 and RS-485 device protocols, NMEA 0183 sentences from GPS receivers (the two hex digits after * are the XOR of every character between $ and *), and some barcode and payment terminals. To verify a received frame, XOR every byte including the BCC: the answer must be 00. Tick Input is ASCII text to checksum an NMEA sentence body directly. For CRC-16, CRC-32, MD5 or SHA checksums, use the checksum calculator instead; XOR is fast but weaker, because two errors in the same bit column cancel out.
XOR encryption, briefly
XORing data with a key is the core step inside real ciphers such as AES and ChaCha20, and with a truly random key as long as the message it is a one-time pad, which is unbreakable. With a short repeating key, as in this tool, it is only obfuscation: common plaintext like spaces or file headers reveals the key quickly. Use it to learn, to decode CTF puzzles and malware strings, or to understand protocols, not to protect secrets. To convert results between bases, see hex to binary and text to hex.
Frequently asked questions
How do you calculate XOR?
Write the values in binary and compare them bit by bit. Each result bit is 1 when the two input bits are different and 0 when they are the same. For example 1100 XOR 1010 = 0110, so 12 XOR 10 = 6. With more than two values, XOR them one after another; the order does not matter.
How do I XOR two hex numbers?
Enter them one per line with a 0x prefix, or choose Hex as the input base, and read the result in hex, decimal and binary. By hand, XOR each hex digit separately: F XOR 3 is C because 1111 XOR 0011 = 1100. So 0xF0 XOR 0x3C = 0xCC.
What is an XOR checksum or BCC?
A Block Check Character is the XOR of every byte in a message. The sender appends it; the receiver XORs all bytes including the BCC and expects 0. It is used in serial protocols, smart cards, barcode scanners and many embedded devices. It catches any single-bit error, but not two errors in the same bit position.
Should the STX byte be included in the BCC?
It depends on the protocol. Many serial protocols compute the BCC over everything after STX up to and including ETX, so tick Skip first byte. Others include every byte. Check the device's documentation, because the same frame gives a different BCC either way.
How does XOR encryption work?
Each byte of the message is XORed with a byte of the key, repeating the key as needed. XORing the result with the same key restores the original, because A XOR K XOR K = A. With a short repeating key it is easy to break and should only be used for learning or obfuscation, not security.
What is the XOR of a number with itself?
Always 0, and XOR with 0 leaves a number unchanged. These two rules make XOR useful for toggling bits, swapping variables without a temporary, finding the one value that appears an odd number of times in a list, and parity checks.
Can I XOR negative numbers or very large numbers?
Yes. The calculator uses arbitrary-precision integers, so values of any length work, and negative numbers are treated as two's complement, as in most programming languages. The binary view pads to a whole number of bytes.