GATE Computer ScienceHardGATE CS (PYQ pattern)
Let g(x) = x XOR (x >> 1) be the 8-bit Gray code of x. For how many x in 0..254 is g(x) equal to x + 1?
- A. 1
- B. 0
- C. 2
- D. 8
Correct answer: A. 1
If x ends in exactly k ones, x + 1 = x XOR (2^(k+1) − 1). So g(x) = x + 1 requires x >> 1 = 2^(k+1) − 1, i.e. x = 2^(k+2) − 2 or 2^(k+2) − 1. The first ends in 0 ones, forcing k = 0 and x = 2 (g(2) = 3). The second ends in k + 2 ones, contradicting k. Only x = 2 works.
More Digital Logic questions
- For how many of the 256 ordered pairs of 4-bit two's complement numbers (a, b) does the exact product a·b fit in a 4-bit two's complement…
- 0.1 stored in IEEE 754 single precision (round to nearest) has the bit pattern 0x3DCCCCCD. Relative to the exact value 0.1, the stored…
- What is the IEEE 754 single-precision bit pattern of the value nearest to −1/3 (round to nearest)?
- Which of the following are true in IEEE 754 arithmetic (using the language operators ==, != and the usual semantics)? Let nan be a NaN and…
- An 8-bit floating-point format has 1 sign bit, 5 exponent bits (bias 15) and 2 fraction bits, with IEEE-style denormals and exponent field…
- An 8-bit floating-point format has 1 sign bit, 5 exponent bits (bias 15) and 2 fraction bits, with IEEE 754-style normalised numbers. How…