home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / programm / 2031 < prev    next >
Encoding:
Text File  |  1992-07-21  |  897 b   |  29 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!usc!cs.utexas.edu!torn!watserv1!watmath!undergrad.math.waterloo.edu!cayley.waterloo.edu!amichail
  3. From: amichail@cayley.waterloo.edu (Amir Michail)
  4. Subject: finding 1st one in integer
  5. Message-ID: <Brqu3F.1J4@undergrad.math.waterloo.edu>
  6. Sender: news@undergrad.math.waterloo.edu
  7. Organization: University of Waterloo
  8. Date: Tue, 21 Jul 1992 14:40:26 GMT
  9. Lines: 18
  10.  
  11. I need a very efficient way of finding the first bit set ( doesn't matter
  12. which side ) in a 32 bit integer. 
  13.  
  14. For example:
  15.  
  16.   binary  -> position
  17.       1 -> 0
  18.     10000 -> 4
  19.      1000 -> 3
  20.  
  21. One can make the simplifying assumption that only 1 bit will be
  22. set in the 32 bit integer (if that helps).
  23.  
  24. Amir
  25.  
  26. P.S.  Please do not tell me to use a large lookup table.  I know about that.
  27.       I also know that the 68020 and 80386 have instructions to do this; I want
  28.       portable C code though.
  29.