counting matching bits / bitXnor

Matthew Fulmer tapplek at gmail.com
Mon Dec 17 17:37:26 UTC 2007


On Mon, Dec 17, 2007 at 01:00:41PM +0100, Cees de Groot wrote:
> It's probably a stupid question that only shows how rusty my bit
> fiddling is - but what would be a *good* performing implementation of
> something that counts matching bits? (for extra credits: if the two
> integers are unequal in size, it's a pattern match so the smaller int
> needs to be shifted along the larger int and the largest count is the
> one that's returned):

doing a google search for "fast bit counting" brings up
http://infolab.stanford.edu/~manku/bitcount/bitcount.html as the
first hit. The first algorithm listed takes time proportional to
the number of 1 bits in the integer, rather than the length of
the bit encoding. It relies on the ability to do a fast zero
check, though, as the loop exit condition

-- 
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808



More information about the Squeak-dev mailing list