BITXOR Function
BITXOR Function

BITXOR Function

Perform a bitwise XOR operation on two integers. Useful for toggling bits, spotting changes, and checking where two bit patterns differ.

ExcelClash Team
PUBLISHED

Summary

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.

Purpose

Keep different bits

Returns only the bits that differ between the two inputs.

Return value

Number

Returns the decimal value of the resulting bit pattern.

Syntax

=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.

Arguments

  • number1 - [required] The first non-negative integer.
  • number2 - [required] The second non-negative integer.

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 vs similar functions

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

Using BITXOR

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!.

Example 1 - Compare 13 and 9

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
Check Answer
Challenge #1
Target: Sheet1!D1

Find the bitwise XOR of 13 and 9.

Example 2 - Toggle bit 8 in 13

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
Check Answer
Challenge #2
Target: Sheet1!D2

Flip bit-4 (8) in a register word value 13.

Example 3 - Compare a value with itself

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
Check Answer
Challenge #3
Target: Sheet1!D3

XOR 127 with 127 to confirm they match (Result 0).

Example 4 - Compare 64 and 1

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
Check Answer
Challenge #4
Target: Sheet1!D4

Audit a data-mask using XOR 64 and 1.

Conclusion Recap

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.

  • Keeps different bits: BITXOR returns only the bits that do not match.
  • Useful for toggling: The same mask can turn a bit on or off.
  • Zero means no difference: If two values are the same, BITXOR returns 0.
  • Returns a number: The result is a decimal value, not a boolean.
  • Works only with non-negative integers: Excel returns #NUM! for values outside the supported range.
Tactical Arena
Share BITXOR Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.