home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!ariel!davidsen
- From: davidsen@ariel.crd.GE.COM (william E Davidsen)
- Newsgroups: comp.arch
- Subject: Re: Finding which bit set in a bit-string.
- Keywords: Bit-counting.
- Message-ID: <1992Jul28.160158.23842@crd.ge.com>
- Date: 28 Jul 92 16:01:58 GMT
- References: <1992Jul27.212607.26361@infonode.ingr.com>
- Sender: usenet@crd.ge.com (Required for NNTP)
- Reply-To: davidsen@crd.ge.com (bill davidsen)
- Organization: GE Corporate R&D Center, Schenectady NY
- Lines: 25
- Nntp-Posting-Host: ariel.crd.ge.com
-
- In article <1992Jul27.212607.26361@infonode.ingr.com>, aaronb@suhana.analog.ingr.com (Aaron B.) writes:
-
- | I posted this on "comp.compression":
- |
- | >Given a bit-string of any size print out the bits set starting with the
- | >least significant bit.
-
- Doing it in C, you don't want a bit by bit test, you want a branch
- table. A byte is too slow with a switch, so use a procedure vector:
-
- void (*showbits[256])();
-
- Then write 256 procedures which each print all the bits set in one
- particular bit pattern. If you want offset from bit zero add it as a
- global variable (passing as arg is slower).
-
- I did a CPU emulator using this once, and it's *fast*, but complex.
- Much faster than any bit by bit operation. Of course you can extend this
- to do 16 bits at a time, or even 32 when you get your 64 bit micro with
- a TB of memory.
- --
- bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
- It never ceases to amaze me that otherwise rational people, able to
- understand calculus, compound interest, and the income tax form, can
- continue to believe that poker is a game of chance.
-