ProgrammingHardGATE CS · TCS NQT

What does this C program print? unsigned int x = 0xB5; printf("%x", x ^ (x >> 1));

  1. A. 1df
  2. B. ef
  3. C. ff
  4. D. 5a

Correct answer: B. ef

x = 1011 0101 and x >> 1 = 0101 1010. Their XOR is 1110 1111 = 0xef, the binary-to-Gray-code conversion. 0xff would be the OR, and 0x5a is the shifted value alone.

More C Programming questions

Exams that ask this topic