home *** CD-ROM | disk | FTP | other *** search
- From: bayes@hplvec.LVLD.HP.COM (Scott Bayes)
- Date: Tue, 19 Jan 1993 17:51:51 GMT
- Subject: Re: (Q) Need bit manipulation algorithm
- Message-ID: <830026@hplvec.LVLD.HP.COM>
- Organization: Hewlett-Packard Co., Loveland, CO
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!hplextra!hpfcso!hplvec!bayes
- Newsgroups: comp.sys.mac.programmer
- References: <1993Jan6.022430.19469@leland.Stanford.EDU>
- Lines: 23
-
- > name, but whose initials are M.A.C. And if you want a solution for
- > a word, and you don't want a 32K lookup table, you actually have to
- > _shift_! Shifting is for weenies.
- >
-
- But for a word, it's just the sum of the bits in each byte. Code something
- like this (untested) should do it PDQ.
-
- ---
-
- * at beginning, d0 contains a word whose "1" bits we wish to count
- * at end, d2 contains number of 1 bits in its lower byte
-
- moveq #0,d1 - clear table index register
- move.b d0,d1 - lower byte of data word
- move.b btable(d1.w),d2 - nbits for lower byte (PC relative)
- lsr.w #8,d0 - access upper byte of data word
- move.b d0,d1 - upper byte of data word
- add.b btable(d1.w),d2 - d2 contains total bits of word
-
- ---
-
- ScottB
-