ProgrammingVery hardProduct company OA

What will be the output of the following pseudocode? (x is an 8-bit unsigned value; & is bitwise AND, | is OR, << and >> are shifts.)

What will be the output of the following pseudocode? (x is an 8-bit unsigned value; & is bitwise AND, | is OR, << and >> are shifts.)
Integer x = 182, r = 0      // 182 = 1011 0110
for (i = 1 to 8)
    r = (r << 1) | (x & 1)
    x = x >> 1
end for
Print r
  1. A. 182
  2. B. 73
  3. C. 109
  4. D. 91

Correct answer: C. 109

The loop moves bits from the low end of x to the low end of r, reversing their order: 1011 0110 → 0110 1101 = 64 + 32 + 8 + 4 + 1 = 109. 91 = 182 >> 1 is a plain shift, not a reversal; 73 = 0100 1001 is the bitwise complement of 182 (0x49).

More Pseudocode and Code Tracing questions

Exams that ask this topic