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
- A. 100
- B. 64
- C. 196
- D. 70
Correct answer: D. 70
100 = 0110 0100 in binary. The expression swaps the two 4-bit halves: 0100 0110 = 64 + 6 = 70.
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? Integer a[7] = {4, 1, 2, 1, 2, 5, 4} Integer x = 0 for (each i from 0 to 6) x = x ^…
- What will be the output of the following pseudocode? Integer a = 29, b = 15, x, c = 0 x = a ^ b while (x > 0) c = c + (x & 1) x = x >> 1…
- What will be the output of the following pseudocode? (integers are two's complement; ~ is bitwise NOT; >> is an arithmetic shift that…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 19, steps = 0, s…
- What will be the output of the following pseudocode? Integer u[1..10], i2 = 1, i3 = 1, i5 = 1, nx u[1] = 1 for (each k from 2 to 10) nx =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, lo = 0, hi =…