ProgrammingHardInfosys · Capgemini pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 182          // binary 1011 0110, 8-bit register
Print x >> 2, (x << 1) & 255, x & (-x)
  1. A. 45 364 2
  2. B. 91 108 2
  3. C. 45 108 2
  4. D. 45 108 4

Correct answer: C. 45 108 2

182 >> 2 = 45 (drop two bits). x << 1 = 364, and & 255 keeps the low 8 bits: 364 − 256 = 108. x & −x isolates the lowest set bit, 0000 0010 = 2.

More Pseudocode and Code Tracing questions

Exams that ask this topic