Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the sum of a XOR (a >> 1) over a = 5, 8 and 13 (where >> is a right shift by one bit)?

  1. A. 31
  2. B. 62
  3. C. 26
  4. D. 30

Correct answer: D. 30

Gray code of a is a XOR (a >> 1): 5 gives 7, 8 gives 12, and 13 gives 11. The total is 30, which is a different quantity from the shifted-left variant.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic