Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: The bit string 1011001 is read as a binary number. What is its value when each bit is XOR-ed with the previous bit (the first bit is kept unchanged), giving a new string, read back in binary?

  1. A. 117
  2. B. 107
  3. C. 110
  4. D. 89

Correct answer: A. 117

Bits 1011001 become 1, 1⊕0, 0⊕1, 1⊕1, 1⊕0, 0⊕0, 0⊕1 = 1110101 = 117, which is n ⊕ (n >> 1), the Gray code of 89. XOR with the next bit gives 107, a running (prefix) XOR gives 110, and 89 is just the original value.

More Coding Interview Problems questions

Exams that ask this topic