Engineering function

BITOR function

Returns a bitwise OR of two numbers: a bit is 1 if it is 1 in either number. Used to combine or switch on flags.

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

BITOR(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 wherever at least one input has a 1.

How BITOR works

BITOR combines two numbers bit by bit and switches on every bit that is on in either of them. Where BITAND tests for flags, BITOR sets them: to give a user the "newsletter" permission (worth 4) without disturbing their other settings, you calculate BITOR(settings, 4). Unlike simply adding 4, BITOR is safe to run twice — if the bit is already on, nothing changes.

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.

Examples

1OR of two numbers

C2fx=BITOR(A2, B2)
ABC
1Number 1Number 2
2231031

Result: 31

23 is 10111 and 10 is 01010; together every bit from 1 to 16 is on: 11111 = 31.

2Switch on a permission flag

C2fx=BITOR(A2, B2)
ABC
1Current flagsFlag to add
25813

Result: 13

The user has flags 1 and 4 (5). Adding the 8 flag gives 13. If the flags had already been 13, the result would still be 13, whereas A2+B2 would wrongly give 21.

⬇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

  • Use BITOR rather than + to set flags; addition breaks if the flag is already set.
  • To clear a flag, combine BITAND with the opposite mask: =BITAND(A2, 255-8) removes the 8 bit from an 8-bit value.

Google Sheets

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

BITOR 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
DanishBITELLER
DutchBIT.OF
FinnishBITTI.TAI
FrenchBITOU
GermanBITODER
HungarianBIT.VAGY
Norwegian (Bokmål)BITELLER
Portuguese (Portugal)BIT.OU
RussianБИТ.ИЛИ
SpanishBIT.O
SwedishBITELLER
TurkishBİTVEYA