ProgrammingVery hardGATE CS · Campus placements

What is the total number of 1 bits in the binary forms of 1, 2, ..., 16 added together?

  1. A. 32
  2. B. 33
  3. C. 40
  4. D. 64

Correct answer: B. 33

Over 0..15 each of the 4 bit positions is set in exactly half the numbers, 4 x 8 = 32 bits, and 16 adds one more for 33. 32 stops at 15, 40 assumes 5 bit positions are each half set, and 64 counts all bits stored rather than set bits.

More C Programming questions

Exams that ask this topic