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?
- A. 128
- B. 32
- C. 64
- 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
- Over all 256 eight-bit patterns x (with −x and x − 1 computed modulo 2⁸), for how many is x & (−x) equal to x ^ (x − 1), where & is…
- An 8-bit two's complement adder computes 3x as (x + x) + x for every x from −128 to 127, setting the overflow flag V separately on each…
- Over all 256 eight-bit patterns, for how many does the value read as sign-magnitude equal the value read as two's complement?
- Over all 256 eight-bit patterns, for how many does the value read as sign-magnitude, as one's complement and as two's complement all…
- The quadratic x² − (13)b·x + (46)b = 0, with coefficients written in base b, has roots 6 and 9. What is b?
- For how many integers n with 2 ≤ n ≤ 30 does the fraction 1/n have a terminating representation in base 6 but a non-terminating one in…