StatGardenREF. DESK
Calculators/Maths/XOR Calculator
Maths

XOR Calculator calculator

Bitwise XOR of two whole numbers, with AND, OR and NOT shown alongside for comparison.

Published 21 August 2026

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

Formulaa XOR b sets each bit to 1 only where the bits of a and b differ; AND sets a bit only where both are 1; OR sets a bit where at least one is 1; NOT flips every bit

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.

TermMeaning
XORExclusive or: 1 where the two bits differ, 0 where they match.
AND1 only where both bits are 1, otherwise 0.
ORInclusive or: 1 where at least one bit is 1, otherwise 0.
NOTFlips every bit of a single number: 1 becomes 0 and 0 becomes 1.
Two's complementThe standard way computers represent negative numbers in binary, used here whenever a result comes out negative.

The inputs explained

FieldWhat to enter
First numberThe first whole number. Decimals are truncated to a whole number before the bitwise operations run.
Second numberThe 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.

a = 45, run against a range of values of b
ba XOR ba AND ba OR b
045045
540545
15341347
4504545
63184563
901198127
25521045255
XOR against 0 leaves a unchanged (45), and XOR against itself always gives 0, since every bit matches its own value. AND and OR do not share that pattern: AND against 0 is always 0, and OR against 0 always returns a unchanged.

What happens when b is 0?

XOR against zero for a handful of different starting numbers.

b held at 0, a varied
aa XOR b
77
2020
4545
100100
255255
XOR-ing any number with 0 always returns that same number, because there is nothing in the second operand to disagree with. This is why 0 is called the identity value for XOR, the same role 0 plays in addition.

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.