BTW – The algo I posted is O(number of set bits). ]]>

You possibly know this, but give a look at the third method for “Counting Bits” in the nice and free PcAsm book (http://www.drpaulcarter.com/pcasm/). I really like this O(log n), but there is a space tradeoff.

Warning: the first method is a spoiler of your post.

all the best,

dadoh