Left Shift and Right Shift Operators
Explore how left shift and right shift operators move bits in C, enabling efficient multiplication and division by powers of two. Understand bit manipulation basics for effective programming.
We'll cover the following...
We'll cover the following...
The left shift operator
The left shift operator is a binary operator that operates on two operands as shown below:
Example
5 << 2 shifts all the bits in 5 two places to the left. The binary of 5 is 00000101; therefore, upon shifting all the bits two places to the left, the answer would be 00010100, which in decimal is 20.
📝 Note: When the bits are shifted to the left, blanks will be created on the right. These blanks will be filled by
0's.
...
Line 9: ...