Number.BitwiseShiftLeft
NumberShifts the bits of an integer left by a specified number of positions.
Syntax
Number.BitwiseShiftLeft(number as number, shift as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | The integer whose bits are shifted. |
shift | number | Yes | The number of bit positions to shift left. Must be a non-negative integer. |
Return Value
number — The integer with bits shifted left by the specified number of positions.
Remarks
Number.BitwiseShiftLeft shifts the binary representation of number to the left by shift positions, filling the vacated low-order bits with zeros. Shifting left by n positions is mathematically equivalent to multiplying by 2^n — as long as the result does not overflow the 64-bit signed integer range.
This is the complement of Number.BitwiseShiftRight. Together, shift operations are used for:
- Constructing bitmasks: Number.BitwiseShiftLeft(1, n) creates a mask with only bit n set
- Packing multiple values: shifting a value into position before OR-ing it into a packed integer
- Fast powers of 2: computing 2^n efficiently (though Number.Power(2, n) is more readable for most cases)
The shift amount should be in the range 0–63 for 64-bit integers. Shifting by 0 returns the original value. The number value is treated as a 64-bit integer; any fractional part is truncated first.
Examples
Example 1: Shift 1 left by 3 positions — equivalent to 1 × 8
Number.BitwiseShiftLeft(1, 3)Result | |
|---|---|
| 1 | 8 |
Example 2: Shift 3 left by 4 positions — equivalent to 3 × 16
Number.BitwiseShiftLeft(3, 4)Result | |
|---|---|
| 1 | 48 |