home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 20950 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.1 KB  |  32 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!mojo.eng.umd.edu!russotto
  3. From: russotto@eng.umd.edu (Matthew T. Russotto)
  4. Subject: Re: (Q) Need bit manipulation algorithm
  5. Message-ID: <1993Jan08.012806.14863@eng.umd.edu>
  6. Date: Fri, 08 Jan 93 01:28:06 GMT
  7. Organization: Project GLUE, University of Maryland, College Park
  8. References: <1993Jan6.022430.19469@leland.Stanford.EDU> <1993Jan6.032113.597@planets.risc.rockwell.com> <20751@ucdavis.ucdavis.edu>
  9. Lines: 21
  10.  
  11. In article <20751@ucdavis.ucdavis.edu> lim@toadflax.cs.ucdavis.edu (Lloyd Lim) writes:
  12. >
  13. >There is a neat trick for counting the number of bits in a word that
  14. >a Microsoft geek showed me one time.  If there are k bits with 1's,
  15. >it runs in O(k) time.
  16.  
  17. They probably use it job interviews....
  18.  
  19. ones = 0;
  20. while (k) {
  21.     k=k&(k-1);
  22.     ones++;
  23. }
  24.  
  25.  
  26.  
  27. -- 
  28. Matthew T. Russotto    russotto@eng.umd.edu    russotto@wam.umd.edu
  29. Some news readers expect "Disclaimer:" here.
  30. Just say NO to police searches and seizures.  Make them use force.
  31. (not responsible for bodily harm resulting from following above advice)
  32.