Bit l shift
BITLSHIFT Function¶
The BITLSHIFT function in Excel performs a bitwise left shift on a given number.
This operation shifts the bits of the binary representation of a number to the left by a specified number of
positions,
with zeros filling in from the right. The function is commonly used in computing scenarios such as binary arithmetic,
power-of-two calculations, and digital logic design.
Key Features of BITLSHIFT:¶
- Shifts the bits in a number to the left by a specified number of places.
- Each left shift effectively multiplies the number by
2^shift_amount. - Returns the decimal equivalent of the resulting binary number after the shift.
Syntax:¶
- number: The decimal number to be shifted. This must be a positive integer.
- shift_amount: The number of bits to shift to the left.
- Must be greater than or equal to 0.
- If
shift_amountis negative, Excel will return a#NUM!error.
Examples:¶
-
Basic Left Shift:
=BITLSHIFT(5, 2)
Binary representation of5is101. Shifting left by 2 positions gives10100, which is20in decimal.
Result:20 -
No Shift:
=BITLSHIFT(8, 0)
Binary representation of8is1000. Left shift by 0 positions results in no change.
Result:8 -
Large Shift:
=BITLSHIFT(3, 3)
Binary representation of3is11. Shifting left by 3 positions gives11000, which is24in decimal.
Result:24 -
Error Due to Negative Shift:
=BITLSHIFT(4, -2)
Negative shift values are not allowed, so Excel will return#NUM!.
Notes:¶
-
Integer Inputs Only:
- Both
numberandshift_amountmust be non-negative integers. - If either input is a fraction or negative, Excel returns a
#NUM!error.
- Both
-
Bitwise Logic:
- Every left shift corresponds to multiplying the number by a power of two:
Result = number * (2^shift_amount).
- Every left shift corresponds to multiplying the number by a power of two:
-
Zero Behavior:
- If
numberis0, the result will always be0, regardless of theshift_amount.
- If
-
Error Handling:
- If inputs are not numeric, Excel will return a
#VALUE!error. - If
numberorshift_amountare negative, Excel will return a#NUM!error.
- If inputs are not numeric, Excel will return a
Applications:¶
-
Use Case:
- The
BITLSHIFTfunction is particularly useful in scenarios where power-of-two multiplications are required. - Commonly used in low-level bit manipulation, binary masking, or encoding data in digital logic.
- The
-
Complementary Functions:
- BITAND: Performs a bitwise AND operation.
- BITOR: Performs a bitwise OR operation.
- BITRSHIFT: Shifts bits to the right by a specified number of places.
- BITXOR: Performs a bitwise XOR operation.