Search⌘ K

Left Shifts

Explore how the left shift operator moves bits to the left, effectively multiplying integers by powers of two. This lesson helps you understand binary representation and apply left shifts to optimize calculations and solve problems efficiently in coding interviews and competitive programming.

We'll cover the following...

Left shift

The left shift operator is written as <<.

Integers are stored in memory as a series of bits. For example, the number 6 stored as a 32-bit int would be:

6 = 00000000 00000000 00000000 00000110

Shifting this bit pattern to the left one position (6 << 1) would result in the number 12:

 6 << 1 = 00000000 00000000 00000000 00001100

As ...