home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!swrinde!emory!ogicse!reed!bowman
- From: bowman@reed.edu (BoBolicious)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: (Q) Need bit manipulation algorithm
- Message-ID: <1993Jan6.040823.23901@reed.edu>
- Date: 6 Jan 93 04:08:23 GMT
- Article-I.D.: reed.1993Jan6.040823.23901
- References: <1993Jan6.022430.19469@leland.Stanford.EDU>
- Organization: Reed College, Portland, OR
- Lines: 24
-
- In article <1993Jan6.022430.19469@leland.Stanford.EDU> felciano@summit.stanford.edu (Ramon M. Felciano) writes:
- >I've got an interesting bit-manipulation problem for you. I need to
- >know how to match a given bit pattern into a stored array of patterns.
- >In particular, I need to come up with a "fuzzy match" if no exact one
- >is found.
-
- The best way I can see to do this is to XOR your test pattern with each member
- of the table. Then the number of "on" bits (the Hamming distance?) is the
- number of bits by which the two patterns differ. I don't know the most
- efficient way to count the number of "on" bits; there are several ways to
- do it, so if you need it to be super-fast, you might want to experiment between
- looping through each bit in the pattern, shifting each time and testing the
- lowest (or highest, depending on which way you shift) bit. Or you could
- maintain a table which contained 1,2,4,8,16,... and AND the result of each
- XOR with each member of *this* table.
-
- Doing the actual bookkeeping to keep track of which one(s) to return and
- by how many bits they differ from the test pattern should be pretty trivial.
-
- cheers,
- bobo In seeking the unattainable,
- bowman@reed.edu simplicity only gets in the way.
- "On Monday, numbers floated everywhere, and the world was full of
- approximations." -- Spencer Heinz, _The Oregonian_, 1/5/93
-