ProgrammingHardGATE CS · Campus placements

For unsigned int n = 13, what is n ^ (n >> 1)? This is the binary-reflected Gray code of 13.

  1. A. 6
  2. B. 7
  3. C. 13
  4. D. 11

Correct answer: D. 11

Gray(n) = n ^ (n >> 1). With 13 = 1101 and 13 >> 1 = 0110, the XOR is 1011, which is 11. Taking only n >> 1 (6) is a common slip.

More C Programming questions

Exams that ask this topic