BITAND Function

BITAND Function

BITAND Function

Perform a bitwise AND comparison on two integers. Useful for masks, flag checks, and pulling out specific bits from a value.

ExcelClash Team
PUBLISHED

Summary

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.

Purpose

Keep shared bits

Returns only the bits that are on in both inputs.

Return value

Number

Returns the decimal value of the filtered bit pattern.

Syntax

=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.

Arguments

  • number1 - [required] The first non-negative integer.
  • number2 - [required] The second non-negative integer.

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 vs similar functions

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

Using BITAND

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!.

Example 1 - Compare 13 and 9

This keeps only the bits that both numbers share.

=BITAND(13, 9) // Returns 9
Check Answer
Challenge #1
Target: Sheet1!F1
Simple Logic Intersection

Find the bitwise AND of 13 and 9. Formula: =BITAND(13, 9).

Example 2 - Check whether bit 8 is set

If the result equals the mask, that bit is on.

=BITAND(12, 8) // Returns 8
Check Answer
Challenge #2
Target: Sheet1!F2
Active Flag Verification

Check if bit 4 (value 8) is set in mask 12. Formula: =BITAND(12, 8).

Example 3 - Test one permission bit

This pulls the execute bit out of a combined permission value.

=BITAND(7, 1) // Returns 1
Check Answer
Challenge #3
Target: Sheet1!F3
Permission Mask Audit

Isolate the "Execute" bit (1) in permission level 7. Formula: =BITAND(7, 1).

Example 4 - Keep only one high bit

This is the same mask idea with a larger value.

=BITAND(1024, 1024) // Returns 1024
Check Answer
Challenge #4
Target: Sheet1!F4
48-Bit Boundary Check

Perform AND on 1024 and 1024. Formula: =BITAND(1024, 1024).

Quick recap

  • Keeps shared bits: BITAND returns only the bits that are on in both inputs.
  • Great for masks: It is one of the easiest ways to test whether a flag is set.
  • Returns a number: The result is a decimal value, not TRUE or FALSE.
  • Use powers of two as masks: Values like 1, 2, 4, and 8 target individual bits.
  • Works only with non-negative integers: Excel returns #NUM! for values outside the supported range.
Tactical Arena
Select Scenario:
Share BITAND Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.