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