home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2318 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.5 KB  |  33 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!usc!venice!reuter
  3. From: reuter@venice.sedd.trw.com (Joseph Reuter)
  4. Subject: Re: finding 1st one in integer
  5. Message-ID: <1992Aug14.153612.13724@venice.sedd.trw.com>
  6. Organization: TRW Systems Engineering & Development Division, Carson, CA
  7. References: <1992Aug9.072022.9391@linus.mitre.org> <H.b_Q8qXezVYo@jonh.wimsey.bc.ca> <Bsx578.CzD@metropolis.com>
  8. Date: Fri, 14 Aug 1992 15:36:12 GMT
  9. Lines: 22
  10.  
  11. In article <Bsx578.CzD@metropolis.com> robert@metropolis.com (Robert Munyer) writes:
  12. >But the point of this discussion is that we're looking for ways to find the
  13. >most significant "one" bit (i.e., count the number of leading 0's) WITHOUT
  14. >having to go through a loop 31 times.
  15. >
  16.  
  17. On the CDC6600, this was accomplished using the floating-point unit, provided
  18. the number in question was less than 2**48.  The number was converted to
  19. unnormalized floating-point by ORing it with 0x200000000000000 and then
  20. normalizing.  The normalize instruction returned the number of left shifts
  21. required, but the count could also be obtained by examining the exponent
  22. part of the normalized floating-point number.
  23.  
  24. I don't know enough about the IEEE floating-point system to know if a
  25. similar trick would work there.  If it does, this technique, while not 
  26. perfectly portable, might be widely applicable.
  27.  
  28. -- 
  29. Joseph A. Reuter, Wizard-in-Training
  30. Speaking for myself from reuter@venice.sedd.trw.com
  31. "Olorin I was in the West that is forgotten." -- J.R.R. Tolkien
  32. "You can't win, you can't break even, and you can't quit the game."
  33.