Skip to main content

Description

Performs a left bit shift operation, moving all bits to the left by the specified number of positions. Zero bits are shifted in from the right.

Syntax

Parameters

Returns

Type: number (integer) The result of shifting the bits left by the specified positions.

Examples

Example 1: Basic Left Shift

Output:
(Binary: 0101 << 2 = 10100 = 20)

Example 2: Multiply by Power of Two

Output:
(Left shift by n is equivalent to multiplying by 2^n)

Example 3: Creating Bit Masks

Output:
(Creates mask with bit 3 set: 1000)

Notes

  • Operates on 32-bit signed integers in JavaScript
  • Left shift by n is equivalent to multiplying by 2^n
  • Bits shifted off the left are discarded
  • Zero bits are shifted in from the right
  • Useful for multiplication by powers of 2 and creating bit masks

See Also

Frequently Asked Questions

It shifts all bits in an integer to the left by the specified number of positions, filling vacated bits with zeros. Each left shift effectively multiplies the value by 2.
The behavior is undefined for negative shift amounts. Always use non-negative integer values for the shift count.