
Perform a bitwise XOR operation on two integers. Useful for toggling bits, spotting changes, and checking where two bit patterns differ.
BITXOR compares two integers at the bit level and keeps only the bits that are different. If the same bit is on in both values or off in both values, the result for that bit is 0.
That makes BITXOR useful for toggling flags and for spotting changes between two bit patterns. It is often the easiest way to answer questions like "what changed?" or "flip this one bit for me."
Returns only the bits that differ between the two inputs.
Returns the decimal value of the resulting bit pattern.
=BITXOR(number1, number2)
number1 and number2 are the integers you want to compare.
Excel compares the two bit patterns and returns 1 only where the bits are different. That makes BITXOR useful for toggling or highlighting change. The result is still shown as a regular decimal number.
Both inputs must be whole numbers greater than or equal to 0. BITXOR is designed for bit patterns stored in decimal form, not text or negative values. If either argument is outside the supported limits, Excel returns an error.
BITXOR is for differences and toggles, not for overlap or simple union:
| Function | What it does | Typical use | Result |
|---|---|---|---|
BITXOR |
Keeps only different bits | Toggle or compare changes | Number |
BITAND |
Keeps only shared bits | Check whether a flag is set | Number |
BITOR |
Keeps any on bit | Turn flags on | Number |
= |
Checks whether two values are equal | Simple value matching | Boolean |
The most common use is toggling a bit with a mask. If the target bit is off, BITXOR turns it on. If the target bit is on, BITXOR turns it off. That is why the same mask can be used to flip a state in either direction.
BITXOR is also useful for comparing two values. If two numbers are identical, their XOR result is 0. If the result is not zero, then at least one bit is different. That makes XOR a compact way to detect a change without comparing bits one by one.
Excel's bitwise functions work with non-negative integers and support values up to 2^48 - 1. If the inputs go outside that range, Excel returns #NUM!.
This keeps only the bits that differ between the two values.
=BITXOR(13, 9) // Returns 4
Find the bitwise XOR of 13 and 9. Formula: =BITXOR(13, 9).
This flips the target bit and leaves the others alone.
=BITXOR(13, 8) // Returns 5
Flip bit-4 (8) in a register word value 13. Formula: =BITXOR(13, 8).
Matching values produce zero because there is no difference left.
=BITXOR(127, 127) // Returns 0
XOR 127 with 127 to confirm they match (Result 0). Formula: =BITXOR(127, 127).
This shows a simple result where the two values have different bits set.
=BITXOR(64, 1) // Returns 65
Audit a data-mask using XOR 64 and 1. Formula: =BITXOR(64, 1).
0.#NUM! for values outside the supported range.Tell your friends about this post