Check Sheet Logo
Check Sheet

BITAND

The BITAND function returns a bitwise AND of two numbers. This function is commonly used in engineering applications where binary digits are manipulated to perform logical operations. The function takes two inputs, value1 and value2, and returns a decimal number that represents the bitwise AND of the two inputs.

Usage

Use the BITAND formula with the syntax shown below, it has 2 required parameters:

=BITAND(value1, value2)
Parameters:
  1. value1 (required):
    The first number to be used in the bitwise AND operation. The number should be an integer or a reference to a cell containing an integer.
  2. value2 (required):
    The second number to be used in the bitwise AND operation. The number should be an integer or a reference to a cell containing an integer.

Examples

Here are a few example use cases that explain how to use the BITAND formula in Google Sheets.

Filtering binary data

When working with data that is represented in binary format, such as network packets or machine code, the BITAND function can be used to filter out specific bits from the data. For example, to extract the third bit from a binary number, you can use BITAND(value, 2) > 0.

Checking for odd or even numbers

The BITAND function can be used to determine whether a number is odd or even. To do this, you can use BITAND(value, 1) = 0 to check if the last bit of the number is 0, which indicates that the number is even.

Extracting specific bit ranges

By using the BITAND function with bit masks, you can extract specific ranges of bits from a binary number. For example, to extract the four bits from positions 5 to 8 in a binary number, you can use BITAND(value, 240) / 16.

Common Mistakes

BITAND not working? Here are some common mistakes people make when using the BITAND Google Sheets Formula:

Missing required arguments

The BITAND function requires two arguments to be provided. If you forget to provide one or both of them, the formula will return an error.

Using non-decimal values

The BITAND function can accept both decimal and hexadecimal values as input. However, you need to make sure that you use the correct prefix (e.g. 0x) for hexadecimal values, otherwise the formula will return an error.

The following functions are similar to BITAND or are often used with it in a formula:

  • BITOR

    The BITOR function returns a bitwise OR of two numbers.

  • BITXOR

    The BITXOR function returns the bitwise XOR of two numbers. The function takes two numeric arguments and returns the result of the bitwise XOR operation performed on them.

  • DEC2BIN

    The DEC2BIN formula is used to convert a decimal number to a binary number. This is commonly used in engineering and computer science to represent numbers in their binary form. The formula takes in a decimal number and an optional number of significant digits to include in the binary representation.

  • BIN2DEC

    The BIN2DEC formula is an engineering formula used to convert a signed binary number to a decimal number. This formula is commonly used in computer science and engineering fields.

Learn More

You can learn more about the BITAND Google Sheets function on Google Support.