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- A. 182
- B. 73
- C. 109
- 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).
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (/ is integer division.) Integer x = 10 x = x + x 2 - 4 / 2 Print x
- What will be the output of the following pseudocode? for (i = 10; i >= 1; i = i - 3) Print i end for
- What will be the output of the following pseudocode? (/ is integer division; + on strings concatenates.) Integer n = 100 String s = ""…
- What will be the output of the following pseudocode? (/ is integer division.) Function f(Integer n) if (n == 0) return 0 end if return (n…
- What will be the output of the following pseudocode? (/ is integer division.) Integer n = 25, z = 0 while (n > 0) n = n / 5 z = z + n end…
- What will be the output of the following pseudocode? Integer s = 0 for (i = 1 to 30) if (i mod 4 == 0) continue end if if (i mod 7 == 0)…