The BITAND function in Google Sheets performs a bitwise logical AND operation on two integers. This function is particularly useful in scenarios involving binary calculations, enabling users to manipulate binary data effectively and derive meaningful insights from it. By evaluating the bit patterns of the numbers, BITAND returns a new integer resulting from the intersection of the bits set in both numbers.
Syntax
BITAND(value1, value2)
- value1: The first integer whose bits will be evaluated.
- value2: The second integer used for the bitwise AND operation.
Example #1
=BITAND(6, 3)
This function evaluates the binary representations of 6 (110) and 3 (011). The result is 2, since only the second bit is set in both numbers. Result: 2.
Example #2
=BITAND(12, 5)
Here, the function takes 12 (1100) and 5 (0101). The overlap in bits results in a return value of 4, as only the third bit is set in both integers. Result: 4.
Example #3
=BITAND(15, 7)
This computes the AND operation for 15 (1111) and 7 (0111). The result is 7, as all bits set in 7 are also set in 15. Result: 7.
Error handling
- VALUE!: This error occurs if either of the arguments is not a valid number.
- NUM!: Returned when the input numbers are below 0, indicating negative integers are not accepted.