Xref: utzoo comp.lang.c:15358 comp.std.c:655 Path: utzoo!attcan!uunet!lll-winken!ames!nrl-cmf!ukma!gatech!bbn!bbn.com!cosell From: cosell@bbn.com (Bernie Cosell) Newsgroups: comp.lang.c,comp.std.c Subject: Re: BIT Counting: C programming problem Message-ID: <34389@bbn.COM> Date: 10 Jan 89 18:15:12 GMT References: <225@tityus.UUCP> Sender: news@bbn.COM Reply-To: cosell@BBN.COM (Bernie Cosell) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 21 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); } __ / ) Bernie Cosell /--< _ __ __ o _ BBN Sys & Tech, Cambridge, MA 02238 /___/_(<_/ (_/) )_(_(<_ cosell@bbn.com