What Left Shift Means
A left shift moves every bit of an integer to the left. Empty positions on the right are filled with zeros. For non-negative integers without fixed-width overflow, this is equivalent to multiplying by a power of two.
Example: the binary number 101 is decimal 5. Shifting left by 2 positions gives 10100, which is decimal 20.
Why This Calculator Uses BigInt
In JavaScript, normal bitwise operators such as << operate on 32-bit signed integers.
That can produce surprising overflow-like results for large values.
Left Shift vs Multiplication
| Shift | Multiplier | Example with 7 |
|---|---|---|
| 7 << 1 | × 2 | 14 |
| 7 << 2 | × 4 | 28 |
| 7 << 3 | × 8 | 56 |
| 7 << 4 | × 16 | 112 |
Binary Example
Input: 1011 Shift: 3 1011 << 3 = 1011000 Decimal: 11 × 2³ = 88
Important Overflow Note
In real programming languages, integers often have fixed sizes such as 8-bit, 16-bit, 32-bit, or 64-bit. If a left shift pushes bits beyond that width, those bits may be discarded or the result may overflow depending on the language and type.
Common Uses
- Multiplying integers by powers of two.
- Creating bit masks.
- Setting bit fields in embedded systems.
- Packing values into binary data structures.
- Understanding low-level computer arithmetic.
Common Mistakes
- Forgetting that JavaScript bitwise shifts are 32-bit.
- Confusing left shift with right shift.
- Using left shift on negative numbers without considering signed representation.
- Ignoring overflow in fixed-width integer types.
- Typing binary values with digits other than 0 and 1.
Frequently Asked Questions
Does left shift always multiply by two?
One left shift multiplies a non-negative integer by two if there is no fixed-width overflow. Shifting by n positions multiplies by 2ⁿ.
What happens when shifting by zero?
The value stays the same. No bits are moved.
Can I enter binary numbers?
Yes. Choose binary input and enter only 0 and 1 digits. You can also include a 0b prefix.
Can I enter hexadecimal numbers?
Yes. Choose hexadecimal input and enter digits from 0 to 9 and A to F. A 0x prefix is also accepted.