counting matching bits / bitXnor

Randal L. Schwartz merlyn at stonehenge.com
Mon Dec 17 16:07:13 UTC 2007


>>>>> "Cees" == Cees de Groot <cdegroot at gmail.com> writes:

Cees> Hi,
Cees> I'm fiddling with some little project where I need to count the number
Cees> of bits that are the same between two bitstrings. My first
Cees> approximation would be to bitXnor: both integers and count bits in the
Cees> result. However, there's no bitXnor: and the standard implementation:

Cees> a XNOR b = (a AND b) OR (NOT a AND NOT b)

Cees> won't fly because there's not bitNot in Integer, as far as I can tell
Cees> (negate draws in all the ugliness of 2-complement arithmetic :)).

That looks like NOT (a XOR b) to me.  Wouldn't that already have
a fast implementation?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



More information about the Squeak-dev mailing list