Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many integers from 1 to 40 inclusive have exactly as many 0-bits as 1-bits in their binary representation (without leading zeros)?

  1. A. 8
  2. B. 7
  3. C. 6
  4. D. 4

Correct answer: B. 7

Count with a direct check over the 40 numbers. The leading 1 bit is not padded, so numbers like 2 (binary 10) qualify while 1 (binary 1) does not.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic