Practice free

BITAND function

BITAND compares two numbers bit by bit and keeps only the bits that are on in both, returning a whole number. It is used to test flags packed into one number.

Example

Read it as a sentence: compare 12 and 10 bit by bit and keep the bits that are on in both, which gives 8.

Practice this in the app

Syntax

BITAND(number1, number2)

number1 (required)
A whole number of 0 or more, below 2^48.
number2 (required)
A second whole number of 0 or more, below 2^48.

Returns: A whole number.

What Excel actually returns

Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.

FormulaExcel showsCase
=BITAND(13,25) 9 13,25
=BITAND(0,0) 0 0,0
=BITAND(2^48-1,1) 1 2^48-1
=BITAND("13","25") 9 Text number
=BITAND(TRUE,1) 1 TRUE
=BITAND({1,2,3},3) 1 Spill
=BITAND(-1,1) #NUM! Negative
=BITAND(1.5,1) #NUM! Decimal

Watch out for

  • Negative or fractional inputs return #NUM!.

Where it works

Excel
BITAND arrived in Excel 2013. Older versions do not have it.
Google Sheets
Same name, same behaviour for everyday use.

Part of Engineering functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .