From: Charles Hixson Date: 2012-10-26T13:41:35+09:00 Subject: Re: bit count or bit set On 10/25/2012 02:00 PM, Bartosz Dziewo��ski wrote: > 2012/10/25 Charles Hixson: >> In Ruby1.9 is there any good way to count the number of on bits in an >> integer (after an& operation)? > number.to_s(2).count('1')? I'm not sure how fast this is going to be, > but might turn out to be faster than a simple while loop. > > -- Matma Rex > > Thank you. I expect that it would be faster than a loop in the Ruby interpreter. I was hoping for some built-in method that I hadn't noticed. (Converting a Fixnum to a bit string should be pretty fast, but it would be clearly faster to skip that step.) -- Charles Hixson