
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."
BITXOR stands out because it is about contrast and toggling, not just combining or filtering. It is useful when the workbook needs to highlight differences between two patterns or flip selected bits with the same mask, which gives it a different role from BITAND and BITOR.
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 example compares two values and keeps only the bit positions that do not match. If a bit is the same in both numbers, it disappears from the final result.
That makes BITXOR useful for difference checks. It helps show what changed between two bit patterns instead of what they share.
=BITXOR(13, 9) // Returns 4
Find the bitwise XOR of 13 and 9.
Here the second value acts like a toggle mask. The bit represented by 8 changes state, while the other bits stay as they were.
That is why XOR is often used for toggling. The same mask can turn a bit off if it is on, or turn it on if it is off.
=BITXOR(13, 8) // Returns 5
Flip bit-4 (8) in a register word value 13.
This example shows the cleanest possible comparison case. Because both inputs are identical, there are no differing bits for BITXOR to return.
The result is 0, which is a useful signal in change detection. If the XOR result is zero, the two bit patterns match exactly.
=BITXOR(127, 127) // Returns 0
XOR 127 with 127 to confirm they match (Result 0).
These two values use different bit positions, so both of those positions appear in the final answer. Nothing cancels out because the bits are not overlapping.
This helps show that XOR is not just for turning things off. It also builds a result that highlights all positions where the inputs differ.
=BITXOR(64, 1) // Returns 65
Audit a data-mask using XOR 64 and 1.
BITXOR is all about difference. In this lesson, it showed that matching bits cancel out while non-matching bits remain, which makes the function useful when you want to highlight changes between two patterns or flip selected flags with a mask.
A practical way to remember BITXOR is that it toggles. If the target bit is off, the mask turns it on, and if the target bit is already on, the same mask turns it off. That makes BITXOR especially helpful when a worksheet needs to switch a bit state instead of only checking or forcing it.
0.#NUM! for values outside the supported range.Tell your friends about this post