## Number of set bits Part II

*February 13, 2009 at 9:35 am* *narinderberi* *
Leave a comment *

Write a function:

int countSetBits(int n);

which gives the total number of set bits (bits which are 1) found while enumerating all integers from 1 to n (in binary of course). What is the complexity of the function?

Entry filed under: Puzzles.

Trackback this post | Subscribe to the comments via RSS Feed