
II-50 Programming Concepts
The syntax of shift left operator is as follows:
Variable << number of bits to shift left.
The difference between shift right and shift left operator is as follows:
1. The shift right operator is used to divide the number by 2.
2. The shift left operator is used to multiply the number by 2.
Example:
Value of i Execution of Each Statement Final Value of i
i = 4 00000100 4
I =i<<1 00001000 8
i =i >> 1 00000010 2
i = i >> 2 00000001 1
32. Which binary shifting is equivalent to multiplying an unsigned number by 2: right
shifting by 1 or left sifting by 1?
Ans: Multiplying an unsigned number by 2 is equivalent to