What this calculator does
XOR, short for "exclusive or", is a bitwise operation that compares two numbers bit by bit and sets each output bit to 1 only where the two inputs disagree: one bit is 1 and the other is 0. Where the bits match, whether both 1 or both 0, the output bit is 0. This calculator works out a XOR b for any two whole numbers, and shows AND, OR and NOT for the same pair so the differences between the four operations are visible side by side.
These operations come from digital logic and programming, not everyday arithmetic, so the numbers you enter are treated as their binary bit patterns rather than as quantities to add or multiply. XOR in particular shows up constantly in code: toggling a flag, swapping two values without a temporary variable, simple checksums and basic encryption all lean on the fact that XOR-ing a value twice with the same key returns the original value.
The formula
Both numbers are converted to their binary representation, and each pair of bits in the same position is compared. XOR outputs 1 for a differing pair and 0 for a matching pair. AND outputs 1 only when both bits are 1. OR outputs 1 when at least one bit is 1. NOT does not compare two numbers at all, it just flips every bit of a single number, which is why it can produce a negative result once JavaScript reads the flipped bit pattern back as a signed number.
| Term | Meaning |
|---|---|
| XOR | Exclusive or: 1 where the two bits differ, 0 where they match. |
| AND | 1 only where both bits are 1, otherwise 0. |
| OR | Inclusive or: 1 where at least one bit is 1, otherwise 0. |
| NOT | Flips every bit of a single number: 1 becomes 0 and 0 becomes 1. |
| Two's complement | The standard way computers represent negative numbers in binary, used here whenever a result comes out negative. |
The inputs explained
| Field | What to enter |
|---|---|
| First number | The first whole number. Decimals are truncated to a whole number before the bitwise operations run. |
| Second number | The second whole number, compared bit by bit against the first. |
When to use it
Checking a toggle or flag calculation
XOR-ing a value against a fixed mask flips only the bits that mask marks, which is how many programs toggle individual flags without disturbing the rest of a byte.
Working through a programming exercise by hand
Bitwise questions in coursework and technical interviews are far easier to check against a calculator that shows the binary alongside the decimal result, rather than converting by hand each time.
Comparing XOR against AND and OR
Seeing all three operations run on the same pair of numbers makes the difference concrete: XOR cares about bits disagreeing, AND cares about both being on, OR cares about either being on.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
How do XOR, AND and OR compare for a = 45?
The same first number, 45 (binary 101101), against several second numbers.
What happens when b is 0?
XOR against zero for a handful of different starting numbers.
Questions
What is XOR used for in practice?
It appears throughout programming: toggling boolean flags, comparing two values for a difference, basic checksums and parity checks, and as a building block in encryption, since XOR-ing the same value twice with the same key returns the original.
Why does NOT sometimes give a negative number?
This calculator works with 32-bit signed integers, the same representation JavaScript uses internally for bitwise operations. Flipping every bit of a positive number typically produces a bit pattern that represents a negative number under two's complement, which is standard behaviour, not an error.
Is XOR the same as "either but not both"?
Yes, that is exactly what exclusive or means. It differs from ordinary OR (sometimes called "inclusive or"), which also counts as true the case where both inputs are 1.
Can I XOR negative numbers?
Yes. Negative numbers are handled using their 32-bit two's complement bit pattern, the same as any programming language's bitwise operators, and the binary shown alongside the result reflects that representation.
For converting the resulting binary values into readable characters, see the binary to text converter.