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)?
- A. 512
- B. 10
- C. 9
- 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
- uint16t x = 0x0F00; uint16t y = x & (uint16t)(0u - x); What is y?
- int a[] = {2, 4, 6, 8}; int p = a + 3, q = a; What does printf("%td", p - q) print?
- char names[3][5] = {"ab", "cde", "f"}; What is strlen(names[1]) + sizeof names[2]?
- A recursive function sums decimal digits: int ds(int n) { return n < 10 ? n : n % 10 + ds(n / 10); }. What is ds(98765)?
- How many 1 bits does 0xDEADBEEF have in binary?
- uint32t value = (uint32t)-1; printf("%d", value == 0xFFFFFFFFu); What is printed?