Left shift (<<) and Right shift (>>) operators are equivalent to _____________ by 2.
Choose the correct words...
Answer: A
Correct answer: Multiplication and Division
Each position in a binary number carries twice the weight of the one to its right, so moving every bit one place left doubles the value and moving it one place right halves it:
\[ n \ll k = n \times 2^{k} \qquad n \gg k = n \div 2^{k} \]
Two cautions attach. The right shift truncates towards zero for unsigned values, discarding the bits shifted out, so it is integer division. And the left shift is a reliable multiplication only for unsigned types, since a signed overflow is undefined behaviour.
Please log in or register to report this question.