ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 13, b = 10       // 1101 and 1010
Print a & b, a | b, a ^ b, ~a      // 32-bit two's complement
  1. A. 8 15 7 2
  2. B. 9 15 6 -14
  3. C. 8 15 7 -14
  4. D. 8 15 7 -13

Correct answer: C. 8 15 7 -14

1101 & 1010 = 1000 = 8; | = 1111 = 15; ^ = 0111 = 7. Bitwise NOT flips every bit, and in two's complement ~a = −a − 1 = −14 (not just the 4 visible bits, which would be 0010 = 2).

More Pseudocode and Code Tracing questions

Exams that ask this topic