Computer Arithmetic

What is the result of arithmetic right-shifting the 8-bit signed integer −8 (1111 1000) by one bit?

  1. A124 (0111 1100)
  2. B−16 (1111 0000)
  3. C−4 (1111 1100)
Show answer and explanation

Answer: C. −4 (1111 1100)

An arithmetic right shift copies the sign bit into the vacated top bit, so 1111 1000 becomes 1111 1100, which is −4 in two's complement. Even for negative numbers, shifting right by one divides by 2. A logical right shift, which inserts 0, gives 0111 1100 = 124, changing the sign. −16 is the result of shifting left by one. Note also that in C, which kind of shift applies to signed integers was historically left to the implementation.

  • A. 124 is the result of a logical right shift inserting 0.
  • B. −16 is the result of shifting left by one.
  • C. Correct. Copying the sign bit gives 1111 1100 = −4.
Practice this topic Back to topic

More Computer Arithmetic questions

  1. In C, what are the results of −7 / 2 and −7 >> 1 (with an arithmetic shift) for int?
  2. In C, what is the result of subtracting 1 from 0 in a 32-bit unsigned integer (unsigned int)?
  3. How is overflow detected when adding two unsigned integers?
  4. Which correctly describes the spacing between adjacent representable floating-point values?
  5. Up to what value can IEEE 754 single precision represent every integer exactly, starting from 0?