ProgrammingHardInfosys SP · Accenture

What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts; 15 = 0000 1111 and 240 = 1111 0000)

What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts; 15 = 0000 1111 and 240 = 1111 0000)
Integer x = 100
Integer y = ((x & 15) << 4) | ((x & 240) >> 4)
Print y
  1. A. 100
  2. B. 64
  3. C. 196
  4. D. 70

Correct answer: D. 70

100 = 0110 0100 in binary. The expression swaps the two 4-bit halves: 0100 0110 = 64 + 6 = 70.

More Pseudocode and Code Tracing questions

Exams that ask this topic