Engineering function

BITXOR function

Returns a bitwise exclusive OR of two numbers: a bit is 1 only where the two numbers differ. Used to toggle flags and compare masks.

Available in Excel 2013 and later, Microsoft 365, Excel for the web, Excel for Mac 2016 and later

Excel 2013 and laterWorks in Google Sheets

Syntax

BITXOR(number1, number2)
ArgumentWhat it means
number1RequiredA whole number from 0 to 2^48 − 1.
number2RequiredA second whole number from 0 to 2^48 − 1.

Returns: A decimal number whose bits are 1 where exactly one input has a 1.

How BITXOR works

BITXOR (exclusive OR) switches a bit on when the two inputs disagree and off when they agree. That makes it the tool for two jobs: toggling a flag (XOR with 4 turns the 4 bit on if it was off and off if it was on) and finding differences between two sets of flags (the result shows exactly which settings changed).

Both inputs are read as binary behind the scenes; you give and get ordinary decimal numbers. They must be whole numbers from 0 up to 2^48 − 1; a negative number, a decimal or a larger value returns #NUM!. If you want to see the bits, wrap the inputs and the result in DEC2BIN (for values up to 511) or BASE.

XOR is also the basis of simple checksums and parity checks: XOR a value with the same key twice and you get the original value back.

Examples

1XOR of two numbers

C2fx=BITXOR(A2, B2)
ABC
1Number 1Number 2
2536

Result: 6

5 is 101 and 3 is 011. The bits differ in the 4 and 2 positions, so the result is 110 = 6.

2Which settings changed?

C2fx=BITXOR(A2, B2)
ABC
1BeforeAfter
213710

Result: 10

Before = 1101, after = 0111. The 8 bit was switched off and the 2 bit switched on, so XOR returns 1010 = 10. =DEC2BIN(C2, 4) shows the changed bits as 1010.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 13 KB

Common errors and how to fix them

ErrorWhy it happensFix
#NUM!A number is negative, has decimals, or is 2^48 (281,474,976,710,656) or more.Use whole numbers from 0 to 281,474,976,710,655. Wrap calculated inputs in INT or ROUND.
#VALUE!An argument is text that is not a number.Convert text such as imported codes with VALUE or HEX2DEC.

Tips

  • XOR twice with the same value restores the original: =BITXOR(BITXOR(A2, 99), 99) returns A2.
  • To count how many bits differ, convert the XOR result to binary and count the 1s: =LEN(SUBSTITUTE(DEC2BIN(C2),"0","")) (for values up to 511).

Google Sheets

BITXOR also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

BITXOR in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishBITXELLER
DutchBIT.EX.OF
FinnishBITTI.EHDOTON.TAI
FrenchBITOUEXCLUSIF
GermanBITXODER
HungarianBIT.XVAGY
Norwegian (Bokmål)BITEKSKLUSIVELLER
Portuguese (Portugal)BIT.XOU
RussianБИТ.ИСКЛИЛИ
SpanishBIT.XO
SwedishBITXELLER
TurkishBİTÖZELVEYA