Bit or
BITOR Function¶
The BITOR function in Excel performs a bitwise OR operation between two numbers.
A bitwise OR compares each bit in the binary representation of two numbers, and the result will have a
bit set to 1 if at least one of the corresponding bits from either number is 1. The function is
commonly used in binary operations, bit masking, and low-level programming tasks.
Key Features of BITOR:¶
- Performs a bitwise OR operation between two decimal numbers.
- Compares the binary representation of the numbers bit by bit.
- Returns a decimal result based on the OR operation performed.
Syntax:¶
- number1: The first non-negative integer.
- number2: The second non-negative integer.
- Both inputs must be integers greater than or equal to
0. - If either number is not an integer or is negative, Excel will return a
#NUM!error.
- Both inputs must be integers greater than or equal to
Examples:¶
-
Basic OR Operation:
=BITOR(5, 3)
Binary representation of5is101, and3is011.
Performing OR gives111, which is7in decimal.
Result:7 -
OR Zero:
=BITOR(6, 0)
Binary representation of6is110, and0is000.
Performing OR gives110, which is6in decimal.
Result:6 -
OR with Itself:
=BITOR(8, 8)
Binary representation of8is1000. Performing OR with itself results in no change.
Result:8 -
Error with Negative Input:
=BITOR(5, -1)
Negative inputs are not allowed, so Excel will return a#NUM!error.
Notes:¶
-
Integer Inputs Only:
- Both
number1andnumber2must be non-negative integers. - If either input is a fraction or negative, Excel returns a
#NUM!error.
- Both
-
Bitwise Logic:
- The result of each bit will be
1if at least one of the corresponding bits is1.
- The result of each bit will be
-
Zero Behavior:
- If either input is
0, the result will be the value of the other number.
- If either input is
-
Error Handling:
- If inputs are not numeric, Excel will return a
#VALUE!error. - If
number1ornumber2are negative, Excel will return a#NUM!error.
- If inputs are not numeric, Excel will return a
Applications:¶
-
Use Case:
- The
BITORfunction is particularly useful for setting specific bits in binary masks. - Commonly used in digital logic, binary encoding, and flag-based programming.
- The
-
Complementary Functions:
- BITAND: Performs a bitwise AND operation.
- BITLSHIFT: Shifts bits to the left by a specified number of places.
- BITRSHIFT: Shifts bits to the right.
- BITXOR: Performs a bitwise XOR operation.