BITAND function
Returns a bitwise AND of two numbers: only the bits that are 1 in both numbers stay on. Great for testing flags and 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
BITAND(number1, number2)| Argument | What it means | |
|---|---|---|
number1 | Required | A whole number from 0 to 2^48 − 1. |
number2 | Required | A second whole number from 0 to 2^48 − 1. |
Returns: A decimal number whose binary bits are 1 only where both inputs have a 1.
How BITAND works
BITAND compares two numbers bit by bit and keeps a bit only when it is switched on in both. Its main real-world use is checking flags: many systems pack several yes/no settings into one number, where 1 means "email allowed", 2 means "SMS allowed", 4 means "newsletter" and so on. BITAND(settings, 4) returns 4 if the newsletter bit is on and 0 if it is off.
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.
Related functions: BITOR switches bits on, BITXOR flips them, and BITLSHIFT / BITRSHIFT move them left or right.
Examples
1AND of two numbers
| A | B | C | |
|---|---|---|---|
| 1 | Number 1 | Number 2 | |
| 2 | 13 | 25 | 9 |
Result: 9
13 is 01101 and 25 is 11001. Only the bits worth 8 and 1 are on in both, so the result is 8 + 1 = 9.
2Does a customer allow the newsletter?
| A | B | C | |
|---|---|---|---|
| 1 | Customer | Permission flags | |
| 2 | Ana | 13 | TRUE |
| 3 | Ben | 3 |
Result: TRUE
Ana's flags are 13 = 8 + 4 + 1, so the 4 bit is on and BITAND returns 4, which is greater than 0: TRUE. Copied down for Ben (3 = 2 + 1) it returns FALSE.
3Keep the lowest byte
| A | B | |
|---|---|---|
| 1 | Value | |
| 2 | 1000 | 232 |
Result: 232
255 is eight 1s, so ANDing with it keeps only the last 8 bits: 1000 − 3×256 = 232. This is the standard way to extract one byte from a packed number.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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
- Test a single bit with
=BITAND(value, 2^n)>0, where n is the bit position counting from 0. - BITAND works on numbers only. If your flags are stored as binary text, convert them with BIN2DEC first.
- Before Excel 2013, people used
=MOD(INT(value/2^n),2)to test bit n; that still works and also handles numbers above 2^48.
Google Sheets
BITAND also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
BITAND 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.
| Language | Function name |
|---|---|
| Danish | BITOG |
| Dutch | BIT.EN |
| Finnish | BITTI.JA |
| French | BITET |
| German | BITUND |
| Hungarian | BIT.ÉS |
| Norwegian (Bokmål) | BITOG |
| Portuguese (Portugal) | BIT.E |
| Russian | БИТ.И |
| Spanish | BIT.Y |
| Swedish | BITOCH |
| Turkish | BİTVE |