Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!xylogics!bu.edu!snorkelwacker!paperboy!osf!dbrooks From: dbrooks@osf.osf.org (David Brooks) Newsgroups: comp.lang.c Subject: Re: count of bits set in a long Keywords: bits set, count of, long Message-ID: <13772@paperboy.OSF.ORG> Date: 25 Sep 90 02:44:39 GMT References: <37545@ut-emx.uucp> Sender: news@OSF.ORG Reply-To: dbrooks@osf.org (David Brooks) Organization: Open Software Foundation Lines: 19 In article <37545@ut-emx.uucp> nwagner@ut-emx.uucp (Neal R. Wagner) writes: > > I need a fast method to count the number of bits that are set in a 32-bit >integer on a Sun 3/80 running 4.0.3 SunOS. I wish people who aren't using the net to do their homework, but look as though they are, would say so. >Is there a faster way in C? How close in speed to a hand-coded assembly >routine would a fast method in C be (after the latter is run through the >optimizer)? Well, if you don't restrict youself to the Sun3, I once knew a machine that could do it in one instruction. I doubt if any compiler could compile your code into that. -- David Brooks dbrooks@osf.org Systems Engineering, OSF uunet!osf.org!dbrooks "A Loaf of Bread, a Jug of Wine, and Six Spades Redoubled -- Omar somebody.