Friday, February 10, 2012

Number of set bits till N

You have given a number N. You need to find out total number of set bits from 0 to N.

Example:
Given number is 5. We can represent number 0 to 5 in binary format as below:
000
001
010
011
100
101
Total set bit are 7 (0+1+1+2+1+2)

1 comment:

  1. http://tech-queries.blogspot.in/2010/12/number-of-set-bits-till-n.html

    ReplyDelete