ProgrammingVery hardGATE CS · Campus placements

How many elements in the 1 to 50 range have exactly three 1 bits in binary?

  1. A. 16
  2. B. 15
  3. C. 20
  4. D. 18

Correct answer: D. 18

Counting by hand or with a loop over popcount gives 18 values with exactly three set bits in 1 to 50.

More C Programming questions

Exams that ask this topic