
Perform a bitwise AND comparison on two integers. Useful for masks, flag checks, and pulling out specific bits from a value.
BITAND compares two integers at the bit level and keeps only the bits that are 1 in both values. If a bit is missing from either side, it becomes 0 in the result.
This makes BITAND very useful for masks and flag checks. Instead of reading every bit manually, you can test whether a specific bit is on by ANDing the value with a mask and looking at the result.
Returns only the bits that are on in both inputs.
Returns the decimal value of the filtered bit pattern.
=BITAND(number1, number2)
number1 and number2 are the integers you want to compare.
Excel compares the two numbers bit by bit and keeps only the positions where both values contain a 1. Even though the logic happens in binary, the returned result is shown as a normal decimal number.
Both arguments must be whole numbers greater than or equal to 0. In practice, these are usually decimal values that happen to represent bit patterns. If an argument is negative, too large, or not numeric, Excel returns an error instead of trying to guess what you meant.
BITAND is for checking overlap between bit patterns, not for adding or toggling them:
| Function | What it does | Typical use | Result |
|---|---|---|---|
BITAND |
Keeps only shared bits | Check whether a flag is set | Number |
BITOR |
Combines bits from both values | Turn flags on | Number |
BITXOR |
Keeps only different bits | Toggle or compare changes | Number |
AND |
Checks logical conditions | TRUE or FALSE tests | Boolean |
The most common pattern is using BITAND with a mask. If you want to know whether a specific bit is on, use the bit's value as the second argument. For example, if the mask is 8, then BITAND(value, 8) returns 8 when that bit is on and 0 when it is off.
This is also useful when a single integer stores several flags at once. Instead of breaking the number apart first, you can test one flag at a time with the matching mask. That keeps the formulas short and makes permission-style values much easier to read.
Excel's bitwise functions work with non-negative integers and support values up to 2^48 - 1. If the inputs go outside that limit, Excel returns #NUM!.
This keeps only the bits that both numbers share.
=BITAND(13, 9) // Returns 9
Find the bitwise AND of 13 and 9. Formula: =BITAND(13, 9).
If the result equals the mask, that bit is on.
=BITAND(12, 8) // Returns 8
Check if bit 4 (value 8) is set in mask 12. Formula: =BITAND(12, 8).
This pulls the execute bit out of a combined permission value.
=BITAND(7, 1) // Returns 1
Isolate the "Execute" bit (1) in permission level 7. Formula: =BITAND(7, 1).
This is the same mask idea with a larger value.
=BITAND(1024, 1024) // Returns 1024
Perform AND on 1024 and 1024. Formula: =BITAND(1024, 1024).
1, 2, 4, and 8 target individual bits.#NUM! for values outside the supported range.Tell your friends about this post