The BITAND function in Google Sheets performs a bitwise AND operation on two numbers, returning a decimal number where each bit is 1 only if both corresponding bits of the inputs are 1. Its syntax is BITAND(value1, value2), and it’s part of the Engineering category, useful for low-level data manipulation, flag testing, and permissions calculations.
What Is a Bitwise AND?
Computers store numbers in binary (base 2), using only 0s and 1s. A bitwise AND compares two numbers bit by bit. For each position, the result bit is 1 only if both input bits are 1; otherwise, it’s 0. For example, the binary of 5 is 101 and 3 is 011. Aligning them:
- 5: 1 0 1
- 3: 0 1 1
- AND: 0 0 1 = 1 (decimal)
So BITAND(5, 3) returns 1. This is a fundamental operation in programming and digital logic, and Google Sheets brings it to spreadsheets for users who need to work with binary data, network masks, or feature flags.
How to Use BITAND in Google Sheets
Using BITAND is straightforward. In any cell, type:
=BITAND(12, 10)
This returns 8 because 12 (binary 1100) and 10 (binary 1010) share only the 8-bit (the third from the right): 1000 = 8. You can also reference cells: if A1 contains 12 and B1 contains 10, =BITAND(A1, B1) gives the same result. The function accepts direct numbers, cell references, or expressions that evaluate to numbers.
Common Use Cases and Examples
BITAND is rarely used in everyday budgeting, but it shines in specific technical scenarios:
- Checking permission flags: If a system stores user permissions as a sum of powers of 2 (e.g., read=1, write=2, execute=4), you can test if a user has write permission by checking
BITAND(permission, 2); if it returns 2, they have it. - Network subnet calculations: Combine BITAND with binary conversions to compute network addresses from IP octets.
- Masking bits: Extract specific bits from a number. For instance, to get the lower 4 bits of a number in A1, use
BITAND(A1, 15)(15 is binary1111).
Example: Suppose cell A1 has the decimal 29 (binary 11101). To see if bit 4 (value 16) is set, use =BITAND(A1, 16); it returns 16 if set, 0 if not.
BITAND vs. Other Bit Functions
Google Sheets offers a family of bitwise functions, each with a distinct purpose:
BITOR(value1, value2)– returns 1 if either bit is 1.BITXOR(value1, value2)– returns 1 if bits differ.BITLSHIFT(value, shift)– shifts bits left, equivalent to multiplying by 2^shift.BITRSHIFT(value, shift)– shifts bits right, equivalent to integer division by 2^shift.
BITAND is the “only both” operation, while BITOR is “at least one” and BITXOR is “exactly one”. These are often used together for complex bit manipulation.
Limitations and Error Messages
BITAND has a few constraints you should know:
- Both arguments must be numeric; text that cannot be coerced to a number returns a
#VALUE!error. - Numbers must be within the 48-bit range (i.e., between -2^47 and 2^47 – 1). Exceeding this gives a
#NUM!error. - Negative numbers are treated as two’s complement, so
BITAND(-1, 5)returns 5 because -1 has all bits set to 1.
If you get an error, check that your inputs are valid numbers and within the range. Also note that BITAND is not available in older versions of Excel; in Excel, use the BITAND function only if you have Excel 2013 or later. In Google Sheets, it works in any modern browser.
BITAND in Google Sheets vs. Excel
Both Google Sheets and Excel have a BITAND function with identical syntax and behavior. The main difference is availability: Excel’s BITAND requires Excel 2013 or later, while Google Sheets includes it for all users. In Excel, the function is under the Engineering category as well. If you’re migrating a spreadsheet from one to the other, BITAND formulas will work without modification, provided the numbers are within the same range limits.
Frequently Asked Questions
Why does BITAND return a decimal number, not binary?
BITAND returns a decimal number because that’s the standard output for arithmetic functions in spreadsheets. To see the binary representation, you can use the DEC2BIN function: =DEC2BIN(BITAND(12,10)) returns 1000.
Can I use BITAND with hexadecimal numbers?
Yes, but you need to convert them first. For example, =BITAND(HEX2DEC("A"), HEX2DEC("5")) converts hex to decimal, performs the AND, and returns a decimal result. To get hex output, wrap with DEC2HEX.
Is BITAND case-sensitive?
No, function names are not case-sensitive. =bitand(1,2) works the same as =BITAND(1,2).
What is the maximum number BITAND can handle?
Google Sheets supports up to 48-bit signed integers, so the maximum positive value is 2^47 – 1 = 140,737,488,355,327. Numbers beyond that trigger a #NUM! error.
How do I check if a number is even using BITAND?
An even number has its least significant bit (bit 0) as 0. So =BITAND(number, 1) returns 0 for even numbers and 1 for odd numbers. For example, =BITAND(4,1) returns 0.
Related
- Fluid Balance Charting: What It Is and Why It Matters
- Battery Backup Calculation for UPS: How to Size Correctly
- Typing Speed Required for Data Entry Jobs
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Double Space in Microsoft Word on Any DeviceTo double-space text in Microsoft Word, select the text—or press Ctrl+A on Windows or Command+A on Mac to…
- Excel NOW Format: Show the Current Date and Time CorrectlyIn Excel, enter =NOW() in a cell to return the current date and time; then format that cell…
- Calculate Age Between Two Dates in ExcelTo calculate a person’s completed age in years between two dates in Excel, enter the birth date in…
- Excel Trust Center: How to Open and Configure SettingsIn Excel for Microsoft 365 on Windows, open the Trust Center by selecting File > Options > Trust…
- Lock an Excel Workbook from Opening with a PasswordTo require a password before anyone can open an Excel workbook, open it in the Excel desktop app,…
- Snowflake SPLIT_PART: Syntax, Examples, and Common IssuesYes—Snowflake has a built-in function called SPLIT_PART for returning one section of a string separated by a delimiter.…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.