0xDE
11 March 2006 @ 11:58 pm
Probably a lot of people know about the tricks in HAKMEM for counting the number of nonzero bits in a machine word. And that in practice it's probably best to avoid multiplication, and either repeatedly remove the lowest nonzero bit with x &= x-1 (if few nonzeros are expected, as in bitboard chess programs) or do a table lookup on longer blocks of bits.

So what follows is not likely to be especially useful.

Read more... )