GATE Computer ScienceVery hardGATE CS (PYQ pattern)

unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u", s, x); What is printed?

  1. A. 895 175
  2. B. 911 236
  3. C. 943 80
  4. D. 911 175

Correct answer: D. 911 175

Each step stays within 8 bits (x << 3 is truncated by the cast, and x >> 2 only shrinks). The six successive values are [163, 149, 50, 138, 236, 175], adding to 911.

More Programming and Data Structures (GATE) questions

Exams that ask this topic