home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!mcsun!sunic!kth.se!byse.nada.kth.se!d88-jwa
- From: d88-jwa@byse.nada.kth.se (Jon WΣtte)
- Subject: Re: (Q) Need bit manipulation algorithm
- Message-ID: <1993Jan11.222234.27054@kth.se>
- Sender: usenet@kth.se (Usenet)
- Nntp-Posting-Host: byse.nada.kth.se
- Organization: Royal Institute of Technology, Stockholm, Sweden
- References: <1993Jan6.022430.19469@leland.Stanford.EDU> <NEERI.93Jan6143512@iis.ethz.ch> <1if329INN2f0@falcon.natinst.com> <1993Jan08.012806.14863@eng.umd.edu> <34440@goofy.apple.COM>
- Date: Mon, 11 Jan 1993 22:22:34 GMT
- Lines: 25
-
- In <34440@goofy.apple.COM> chris_russo@gateway.qm.apple.com (Christopher Russo) writes:
-
- >>>There is a neat trick for counting the number of bits in a word that
- >>>a Microsoft geek showed me one time. If there are k bits with 1's,
- >>>it runs in O(k) time.
-
- >I learned a cool way in an interview here at Apple. For the number of
- >bits in a byte, all you'd need is a 256 byte look-up table where the
- >index designated by, say, 00001010 would be index $A into the table which
- >would contain the number 2 (that you put there.) It's pretty fast.
-
- Yes, but it runs in O(b) time, where b is the number of bits
- (i.e. one table lookup for each byte in the word) It's not even
- a neat trick; it's one of those friggin obvious things that
- someone probably patented :-)
-
- I still want to know the O(number-of-bits-set) algorithm.
-
- Cheers,
-
- / h+
- --
- -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
- This signature is kept shorter than 4 lines in the interests of UseNet
- S/N ratio.
-