Machine-translated by Google. Questions are authored in English.
Top

Discussion

On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right?

  • A.True
  • B.False

Answer: B

Correct answer: False

C's shift operators do not rotate. On a left shift the bits leaving the top are simply discarded, and zeros are brought in at the bottom - nothing wraps around.

Rotation exists in most processors as a machine instruction but has no operator in C, and must be written out: (x << k) | (x >> (n-k)) on an unsigned type of \( n \) bits, which reintroduces at the bottom the bits the left shift discarded. Discarding rather than rotating is what makes a left shift a multiplication by two.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.