ProgrammingVery hardGoldman Sachs OA · Amazon OA
What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts)
What will be the output of the following pseudocode? (& is AND, | is OR, << and >> are shifts)
Integer x = 43 Integer y = ((x & 170) >> 1) | ((x & 85) << 1) Print y
- A. 43
- B. 86
- C. 21
- D. 23
Correct answer: D. 23
170 = 10101010 and 85 = 01010101 pick out the odd and even bit positions; shifting them towards each other swaps every adjacent pair of bits. 43 = 00101011 becomes 00010111 = 23.
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? (All variables are integers, so / is integer division; & is AND, ^ is XOR, | is OR…
- What will be the output of the following pseudocode? Integer n = 3524, steps = 0 while (n != 6174) Integer big = digits of n sorted in…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer total = 0, n for (each…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) Function…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {2, 5, 9}, {4, 6, 0}} Integer bad = 0 for (each i from…
- What will be the output of the following pseudocode? (operands are evaluated strictly left to right) Integer a = 7, b = 3 a = a + b - (b =…