ProgrammingHardTCS NQT · Infosys

What is the index of the highest set bit of 1000 (so 2^index is the largest power of two that is at most 1000)?

  1. A. 512
  2. B. 10
  3. C. 9
  4. D. 3

Correct answer: C. 9

512 = 2^9 <= 1000 < 1024 = 2^10, so the highest set bit is index 9, i.e. floor(log2 1000). 10 is the bit length (indices start at 0), 512 is the value of that bit rather than its index, and 3 is the lowest set bit of 1000 = 1111101000.

More C Programming questions

Exams that ask this topic