On 10/25/2012 02:00 PM, Bartosz Dziewoski wrote:
> 2012/10/25 Charles Hixson<charleshixsn / earthlink.net>:
>> 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