Contact

BITXOR in Excel: Find Changed Flags and Toggle Bits

Engineering Intermediate Microsoft Excel

Compare bit masks with Excel BITXOR, identify changed flags, toggle a selected bit and distinguish differences from merged settings.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: BITXOR(number1,number2) returns the decimal mask of positions where the two inputs have different bits. It is useful for identifying changed flags or toggling specific bits; equal bit positions become zero.

Availability and version history

  • Introduced: the Microsoft function catalogue marks this identity as an Excel 2013 addition. An exact first build or preview date is not established.
  • Availability: official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016.
  • Checked: October 14, 2026; official BITXOR reference. Documentation and independent models; no native Excel execution or wider platform certification.

Syntax and limits

=BITXOR(number1,number2)

Both arguments are required and must be nonnegative. Microsoft’s reference limits each input to 2^48−1, or 281474976710655; out-of-constraint inputs produce #NUM!, and nonnumeric inputs produce #VALUE!.

Use nonnegative integers for the documented bit comparisons below. The short reference does not explicitly settle fractional-input behavior, so no cross-function truncation or error rule is assumed here. The worked examples also avoid large-number precision boundaries and text coercion.

BITXOR compares each bit position independently. It is different from the logical XOR function, which evaluates logical conditions and returns TRUE or FALSE. BITXOR returns a decimal number representing multiple changed positions.

Example 1: find which report flags changed

Define fictional report flags as summary=1, detail=2, chart=4 and appendix=8. Enter the following in A1:B4:

A, old mask B, new mask
13 11
5 5
0 10

In C2 enter and fill through C4:

=BITXOR(A2,B2)

The expected results are 6, 0 and 10. In the first row, 13 is 1101 and 11 is 1011. The differing positions are 0110, or 4+2=6. Chart and detail changed; summary and appendix did not.

In E2:E5 enter 1, 2, 4 and 8. In F2 use =BITAND($C$2,E2)>0 and fill through F5. The outputs are FALSE, TRUE, TRUE and FALSE, identifying the two changed flags.

This difference mask does not itself say whether a changed flag was enabled or disabled. Inspect the old and new masks as well: detail was absent in 13 and present in 11, whereas chart was present in 13 and absent in 11.

Example 2: toggle one bit deliberately

Enter masks 1, 5, 8 and 12 in H2:H5. To reverse the chart flag, use weight 4:

=BITXOR(H2,4)

Enter the formula in I2 and fill through I5. The outputs are 5, 1, 12 and 8. If chart was absent it becomes present; if present it becomes absent.

In J2 enter =BITXOR(I2,4) and fill down. The results return to 1, 5, 8 and 12. Applying the same toggle twice cancels it.

For a repeatable operation that must ensure chart is enabled, BITOR is the appropriate operation: =BITOR(H2,4) returns 5, 5, 12 and 12. Repeating an enable operation should not disable an existing flag.

Advanced example: distinguish added and removed flags

Keep the first old/new pair, 13 and 11, in A2:B2 and its difference mask 6 in C2. Use:

=BITAND(C2,B2)
=BITAND(C2,A2)

The first result is 2, the changed bit present in the new mask. The second is 4, the changed bit present in the old mask. Thus detail was added and chart was removed.

For unchanged masks 5 and 5, both added and removed masks are zero. For old=0 and new=10, added is 10 and removed is zero. These controls distinguish a no-change record from a real change to or from zero.

You can reconstruct the new mask with =BITXOR(A2,C2), yielding 11. This is an algebraic consistency check for the same stored values, not an integrity or security guarantee. Keep the original old and new columns if you need an auditable change log.

Common misunderstandings

  • =BITXOR(5,3) returns 6 because 101 and 011 differ in the 4 and 2 positions.
  • =BITOR(5,3) returns 7 because it retains every bit present in either mask.
  • =BITXOR(9,9) returns 0; =BITXOR(9,0) returns 9.
  • The numeric difference =11-13 is −2, which is not the changed-bit mask 6.

A mask is a compact encoding only when every weight has an agreed meaning. Do not use this operation as encryption or as proof that a change was authorized. BITAND provides the separate tests used to inspect each flag, while ordinary worksheet comparisons can confirm whether complete masks are equal.

References and verification

Expected outputs are independently calculated examples or documented rules, not captured native Excel results. Formulas use English function names and comma argument separators. Locale, rendering and boundary restrictions are stated where relevant.