GATE Computer ScienceEasyGATE CS (PYQ pattern)

For an 8-bit signed integer x (−128 to 127), x >> 2 is an arithmetic right shift (sign bit replicated) and x / 4 is division truncated toward zero, as in C. For how many of the 256 values of x do the two results differ?

  1. A. 128
  2. B. 32
  3. C. 64
  4. D. 96

Correct answer: D. 96

An arithmetic shift rounds toward −∞ while truncating division rounds toward 0. They agree for all x ≥ 0 and for negative multiples of 4. The 128 negative values contain 32 multiples of 4, so they differ for 128 − 32 = 96 values (e.g. −5 >> 2 = −2 but −5 / 4 = −1).

More Digital Logic questions

Exams that ask this topic