count of bits set in a long

Tim W Smith ts at cup.portal.com
Wed Sep 26 22:46:35 AEST 1990


How about something like this?

int	NumberOfBitsInLong( register unsigned long input )
{
	register int count;

	for ( count = 0; input != 0; count++ )
		input &= input-1;

	return count;
}

						Tim Smith



More information about the Comp.lang.c mailing list