Xref: utzoo comp.lang.c:15380 comp.std.c:660 Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!purdue!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c,comp.std.c Subject: Re: BIT Counting: C programming problem Message-ID: <1171@goofy.megatest.UUCP> Date: 10 Jan 89 23:44:47 GMT References: <34389@bbn.COM) Organization: Megatest Corporation, San Jose, Ca Lines: 23 From article <34389@bbn.COM), by cosell@bbn.com (Bernie Cosell): ) In article <225@tityus.UUCP) jim@athsys.uucp (Jim Becker) writes: ) } ) } The problem is the most efficient method to simply count the ) }number of on bits in a sixteen bit short. ) ) 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."