home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch
- Path: sparky!uunet!infonode!ingr!analog!suhana!aaronb
- From: aaronb@suhana.analog.ingr.com (Aaron B.)
- Subject: Finding which bit set in a bit-string.
- Message-ID: <1992Jul27.212607.26361@infonode.ingr.com>
- Keywords: Bit-counting.
- Sender: harun@suhana (Aaron B.)
- Reply-To: aaronb@suhana.analog.ingr.com
- Organization: Home Office Enterprise
- Date: Mon, 27 Jul 1992 21:26:07 GMT
- Lines: 76
-
-
- Article: 93 of comp.compression.research
- Path: infonode!uunet!dtix!darwin.sura.net!mips!zaphod.mps.ohio-state.edu!caen!nic.umass.edu!dime!dime.cs.umass.edu!moss
- From: moss@cs.umass.edu (Eliot Moss)
- Newsgroups: comp.compression.research
- Subject: Re: Algorithm for finding set bits in a bit-string.
- Message-ID: <MOSS.92Jul25222337@ibis.cs.umass.edu>
- Date: 26 Jul 92 02:23:37 GMT
- References: <1992Jul26.010325.9885@infonode.ingr.com>
- Sender: news@dime.cs.umass.edu
- Reply-To: moss@cs.umass.edu
- Organization: Dept of Comp and Info Sci, Univ of Mass (Amherst)
- Lines: 17
-
- I posted this on "comp.compression":
-
- >Given a bit-string of any size print out the bits set starting with the
- >least significant bit.
-
- And somebody reply with this:
-
- >In-reply-to: aaronb@suhana.analog.ingr.com's message of 26 Jul 92 01:03:25 GMT
- >The "find first set bit" operation was recently discussed at length in
- >comp.arch, and could be relevant, especially if the one bits are sparse.
-
- My question is: did anybody follow this thread in this group. Is there anyway
- I could get access to the archive of this group. If anybody had save the
- postings on this topic please E-mail me a copy.
-
-
- This is my current solution for this problem. If anybody have a better one
- please E-mail your response. Thanks.
-
-
- static unsigned char binvalue[9]={0x00, 0x01, 0x02, 0x04, 0x08,
- 0x10, 0x20, 0x40, 0x80 };
-
- int
- show_msb(ch, off)
- unsigned char ch;
- long off;
- {
- int pos;
-
- if ( ch )
- {
- pos = ilog2( ch );
- printf("position = %d\n",pos+off);
- ch ^= binvalue[pos]; /* could also use: ch -= binvalue[pos]; */
- show_msb(ch, off); /* recursive call for rest of bits */
- }
- return( 0 );
- }
-
- int
- ilog2(n)
- register unsigned char n;
- {
- register long q;
-
- q = 0;
- while( n )
- {
- n >>= 1;
- q++;
- }
- return( q );
- } /* ilog2 */
-
-
- Thanks in advance.
-
- Aaron B
- aaronb@suhana.analog.ingr.com
-
-
-