count of bits set in a long
Bill Parke
parke at star.enet.dec.com
Thu Sep 27 06:39:23 AEST 1990
In article <34281 at cup.portal.com>, ts at cup.portal.com (Tim W Smith) writes:
|> From: ts at cup.portal.com (Tim W Smith)
|> Newsgroups: comp.lang.c
|> Subject: Re: count of bits set in a long
|>
|> How about something like this?
|>
|> int NumberOfBitsInLong( register unsigned long input )
^^^^^^^^
Not necessary
|> {
|> register int count;
|>
|> for ( count = 0; input != 0; count++ )
|> input &= input-1;
This will count bits in a signed number (see
my previous posting of this using "while" )
|>
|> return count;
|> }
|>
|> Tim Smith
|>
--
Bill Parke parke%star.enet.dec at decwrl.dec.com
VMS Development decwrl!star.enet.dec.com!parke
Digital Equipment Corp parke at star.enet.dec.com
110 Spit Brook Road ZK01-1/F22, Nashua NH 03063
The views expressed are my own.
More information about the Comp.lang.c
mailing list