The Left-Shift Operator
When a left-shift operation is performed on a value, the bits contained in the value are literally shifted to the left. Associated with this operation is the number of places (bits) that the value is to be shifted. Bits that are shifted out through the high-order bit of the data item are lost, and 0s are always shifted in through the low-order bit of the value. So, if w1 is equal to 3, the expression
w1 = w1 << 1;
which can also be expressed as
w1 <<= 1;
results in 3 being shifted one place to the left, which will result in 6 being assigned to w1:
w1 ... 0000 0011 0x03w1 << 1 ... 0000 0110 0x06
The operand on the left of the << operator is the value to be shifted, whereas the operand on the right is the number ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access