Xor Calculator
Compute XOR for two numbers in binary, octal, or decimal. Pick bit size, enter values, and copy the XOR result for coding and quick checks.
Xor Calculator
You can write binary numbers with no more than 4 digits.
Result will appear here...
What the XOR calculator does
This works out the XOR, the exclusive OR, of two numbers, comparing them bit by bit. It lays out both numbers and the result in binary so you can see exactly which bits came out 1, and also gives the result in octal and decimal.
XOR is the quiet workhorse of bit operations. It looks simple, just a comparison, but it has one property that the others lack, and that property is what makes it turn up in toggles, checks, and even simple encryption.
How to use it
- Choose a bit width and data type. The width sets how many bits the numbers use; the data type lets you enter them in binary, octal, or decimal.
- Enter the two numbers. XOR always works on a pair.
- Press Calculate. You will see both inputs in binary, lined up, and the XOR result beneath them.
Press Reset to clear the inputs.
The rule: spot the difference
XOR compares the two numbers one bit position at a time and asks a single question in each: are these two bits different? If they differ, one being 1 and the other 0, the result bit is 1. If they match, both 0 or both 1, the result bit is 0. So XOR is really a difference detector. Take 1100 XOR 1010: the two middle columns differ and the outer two match, so the result is 0110. Every 1 in the answer marks a spot where the two numbers disagreed.
How XOR differs from OR
XOR and OR are easy to mix up, because they agree most of the time. Both give 1 when exactly one bit is 1. They part ways in only one case: when both bits are 1. OR still says 1, because either being on is enough. XOR says 0, because the two bits are the same, not different. So OR asks is at least one on, while XOR asks is exactly one on. That single difference is the whole personality of XOR.
The property that makes XOR special
Here is the part that sets XOR apart: it undoes itself. Applying the same value twice brings you right back where you started. The reason is two small facts. A number XORed with itself is all zeros, since every bit matches itself. And a number XORed with zero is unchanged. Put those together and XORing by some value twice cancels out, so if you take a number, XOR it with a key, then XOR by that same key again, you get your original number back. None of AND, OR, or NOT can be reversed like that, and it is the foundation of most of XOR's tricks.
What people use XOR for
That reversibility shows up everywhere. The simplest use is toggling: XOR a bit with 1 to flip it, or with 0 to leave it alone, which lets you switch chosen switches without disturbing the rest. The most striking use is a basic cipher. Take a message, XOR it with a secret key, and you get scrambled output; XOR that output with the same key and the message comes straight back. The same idea lets you compare two things for equality, since matching values XOR to all zeros, and it is a quick way to clear a value to zero by XORing it with itself.
Questions people ask
What does XOR do?
It compares two numbers bit by bit and gives 1 wherever the bits differ and 0 wherever they match. The 1s in the result mark every position where the two numbers disagreed.
How is XOR different from OR?
They differ only when both bits are 1. OR gives 1 because either is on; XOR gives 0 because the bits are the same. OR asks is at least one on, XOR asks is exactly one on.
Why is XOR reversible?
Because a value XORed with itself is zero and a value XORed with zero is unchanged. So XORing by the same key twice cancels out and returns the original number.
How can XOR encrypt a message?
XOR the message with a secret key to scramble it, then XOR the scrambled result with the same key to recover the message. The reversibility is what makes the round trip work.
References
- Weisstein, Eric W. "XOR." From MathWorld, A Wolfram Resource. https://mathworld.wolfram.com/XOR.html
- Exclusive or. Wikipedia, The Free Encyclopedia. https://en.wikipedia.org/wiki/Exclusive_or
Ankit Khatiwada is a researcher and graduate student in Computer Science at Saarland University, with strengths in statistics, data analysis, data engineering, and full stack development. His work sits at the intersection of quantitative reasoning and applied technology, making him a strong fit for tools that depend on clear numerical logic. At Eon Tools, he reviews number and statistical tools.