Left Shifts
The left-shift operator causes the bits in shift-expression to be shifted to the left by the number of positions specified by additive-expression. The bit positions that have been vacated by the shift operation are zero-filled
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 ...