GATE Computer ScienceHardGATE CS (PYQ pattern)
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 bitwise AND and ^ is bitwise XOR?
- A. 128
- B. 129
- C. 9
- D. 127
Correct answer: A. 128
For x ≠ 0 with lowest set bit L = 2^k: x & (−x) = L, while x ^ (x − 1) flips bit k and every bit below it, giving 2L − 1. These are equal only when L = 1, i.e. x is odd: 128 values. For x = 0: 0 & 0 = 0 but 0 ^ 0xFF = 0xFF, so it fails. Answer 128.
More Digital Logic questions
- 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…
- Values from −1000 to +1000 must be stored with a resolution of at least 0.0001. Design (i) is a two's complement binary fixed-point format…