home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!usc!cs.utexas.edu!torn!watserv1!watmath!undergrad.math.waterloo.edu!cayley.waterloo.edu!amichail
- From: amichail@cayley.waterloo.edu (Amir Michail)
- Subject: finding 1st one in integer
- Message-ID: <Brqu3F.1J4@undergrad.math.waterloo.edu>
- Sender: news@undergrad.math.waterloo.edu
- Organization: University of Waterloo
- Date: Tue, 21 Jul 1992 14:40:26 GMT
- Lines: 18
-
- I need a very efficient way of finding the first bit set ( doesn't matter
- which side ) in a 32 bit integer.
-
- For example:
-
- binary -> position
- 1 -> 0
- 10000 -> 4
- 1000 -> 3
-
- One can make the simplifying assumption that only 1 bit will be
- set in the 32 bit integer (if that helps).
-
- Amir
-
- P.S. Please do not tell me to use a large lookup table. I know about that.
- I also know that the 68020 and 80386 have instructions to do this; I want
- portable C code though.
-