ProgrammingModerateTCS 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 a = 5
Print (a << 2) + (a >> 1)
  1. A. 12
  2. B. 22
  3. C. 25
  4. D. 20

Correct answer: B. 22

Shifting left by 2 multiplies by 4: 5 << 2 = 20. Shifting right by 1 halves and drops the fraction: 5 >> 1 = 2. Total 22.

More Pseudocode and Code Tracing questions

Exams that ask this topic