Xref: utzoo comp.lang.c:15443 comp.std.c:669 Path: utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!nosc!ucsd!ucbvax!hplabs!pyramid!infmx!greggy From: greggy@infmx.UUCP (greg yachuk) Newsgroups: comp.lang.c,comp.std.c Subject: Re: BIT Counting: C programming problem Message-ID: <755@infmx.UUCP> Date: 12 Jan 89 01:14:15 GMT References: <34389@bbn.COM) <1171@goofy.megatest.UUCP> Reply-To: greggy@infmx.UUCP (greg yachuk) Organization: Informix, Menlo Park, Ca. U.S.A. Lines: 22 In article <1171@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: :From article <34389@bbn.COM), by cosell@bbn.com (Bernie Cosell): :) :) Try this: :) :) int BitCount(num) :) short num; :) { :) int count = 0; :) :) while (num != 0) :) num &= num-1, count += 1; :) return (count); :) } :) : :Note well that he did not claim that it works. He only said, "Try this." Guess what, Dave. It *does* work. Check it out manually, if necessary! Greg Yachuk Informix Software Inc., Menlo Park, CA (415) 322-4100 {uunet,pyramid}!infmx!greggy why yes, I DID choose that login myself