Category: FUNCTION | Updated: 2026-11-22

How to Use the BITAND Function in Google Sheets | Calculate Bitwise AND of Two Numbers

Syntax

=BITAND(value1, value2)
  • value1: Specifies the first non-negative integer for the bitwise AND operation.
  • value2: Specifies the second non-negative integer for the bitwise AND operation.

Practical Example with a Table

Here is an example of comparing two integers bit by bit, keeping only bit positions where both are 1, and returning the decimal result.

Value 1 (Binary) Value 2 (Binary) Formula Result How It Works
13 (1101) 25 (11001) =BITAND(A2, B2) 9 01101 AND 11001 = 01001 (9)
5 (101) 3 (011) =BITAND(A3, B3) 1 101 AND 011 = 001 (1)
12 (1100) 3 (0011) =BITAND(A4, B4) 0 No overlapping 1 bits → 0
6 (110) 4 (100) =BITAND(A5, B5) 4 Checks whether the 4-bit is set

Common Errors and Notes

  • #NUM! Error: Occurs if value1 or value2 is negative (less than 0), a decimal fraction, or greater than 281,474,976,710,655 (2^48 - 1).
  • #VALUE! Error: Occurs if an argument is a non-numeric string.
  • Related Bitwise Functions: You can similarly use BITOR for bitwise OR, BITXOR for bitwise XOR, and BITLSHIFT / BITRSHIFT for bit shifting.

Frequently Asked Questions

Q. What are common use cases for the BITAND function?

A. It is often used for flag checks (bitmasks). For example, when permissions or statuses are stored as sums of powers of 2 (1, 2, 4, 8...), you can check whether a specific flag is set using `BITAND(value, flag) > 0`.

Q. Can I enter negative numbers or decimals into the BITAND function?

A. No. BITAND only supports non-negative integers (0 to 2^48 - 1). Entering negative numbers or decimals triggers a "#NUM!" error.