From: Charles Hixson Date: 2012-10-26T05:53:36+09:00 Subject: bit count or bit set In Ruby1.9 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use Fixnums, as I'm probably going to need thousands of these, if the tests work out. But before I can test, I need a decent bit counter. (shift, xor, &, and | are already present for integer values, but I also need to count the number of "true" items after the logical operation. So if a bitset is the correct approach, I'll need it to implement those operations, or their equivalents in terms of union and intersection.) Or do I need to drop into C for this? -- Charles Hixson