ProgrammingHardTCS NQT · Accenture pattern

What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)

What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)
Integer x = 13
Print x ^ (x >> 1)
  1. A. 9
  2. B. 6
  3. C. 7
  4. D. 11

Correct answer: D. 11

13 = 1101 and 13 >> 1 = 0110. XOR gives 1011 = 11. (This is the Gray code of 13.)

More Pseudocode and Code Tracing questions

Exams that ask this topic