Home » Excel-Built-In-Functions » Excel-Engineering-Functions » Excel-Bitand-Function
The Excel BITAND Function
Bitwise Functions
The Excel Bitwise functions convert the supplied integer value(s) to binary form and then perform an operation on the individual bits.
The result is then converted back to an integer value before being returned.
Further information on Bitwise operations is provided on the Wikipedia Bitwise Operation Page
Function Description
The Excel BitAnd function returns the bitwise 'AND' for two supplied integers.
Note: the BitAnd function was only introduced in Excel 2013 and so is not available in earlier versions of Excel.
The syntax of the function is:
BITAND( number1, number2 )
where the supplied number arguments are positive integers.
BitAnd Function Examples
Example 1
Formula: | A | B |
---|
1 | =BITAND( 5, 7 ) | (5 and 7 have binary forms 101 and 111) |
---|
2 | | |
---|
| Result: | A | B |
---|
1 | 5 | (decimal form of 101) |
---|
2 | | |
---|
|
Decimal-Binary Conversion
If you want to work through the stages of a bitwise 'AND' operation you can use the Excel
DEC2BIN and
BIN2DEC functions to convert between decimal and binary forms.
In the above example:
- The binary form of 5 is 101.
- The binary form of 7 is 111.
- The two binary numbers 101 and 111 both have the digit '1' at positions 1 and 3 (counting from the right).
- The bitwise 'AND' result is therefore the binary number that has a '1' in positions 1 and 3 (from the right). I.e. the binary number 101.
- This number is returned in decimal form, as the integer 5.
Example 2
Formula: | A | B |
---|
1 | =BITAND( 13, 14 ) | (13 and 14 have binary forms 1101 and 1110) |
---|
2 | | |
---|
| Result: | A | B |
---|
1 | 12 | (decimal form of 1100) |
---|
2 | | |
---|
|
In the above example:
- The binary form of 13 is 1101.
- The binary form of 14 is 1110.
- The two binary numbers 1101 and 1110 both have the digit '1' at positions 3 and 4 (counting from the right).
- The bitwise 'AND' result is therefore the binary number that has a '1' in positions 3 and 4 (from the right). I.e. the binary number 1100.
- This number is returned in decimal form, as the integer 12.
Further information and examples of the Excel BitAnd function are provided on the Microsoft Office website.
BitAnd Function Errors
Common Errors
#NUM! | - | Occurs if either: - One or both of the supplied number arguments is a non-integer;
- One or both of the supplied number arguments is negative or is greater than (2^48)-1.
|
#VALUE! | - | Occurs if one or both of the supplied number arguments is non-numeric. |