Number of set bits Part II

February 13, 2009 at 9:35 am 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?

Advertisements

Entry filed under: Puzzles.

Move Ladybird Move! All Correct!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Blog Stats

  • 4,036 hits

Recent Comments


%d bloggers like this: