#define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
#define BX_(x) ((x) - (((x)>>1)&0x77777777) \
- (((x)>>2)&0x33333333) \
- (((x)>>3)&0x11111111))
int main(){int a;printf("Enter an int: ");scanf("%d",&a);
return printf("No of 1 bits: %d\n",BITCOUNT(a));}
I found the #defines in one of my fortune files. Added the mail function.
I haven't thought about it much, but can't figure out how it works so
well.
Philip
=======================================================================
Four thousand throats may be cut in one night by a running man.
-- Klingon Soldier, "Day of the Dove", stardate unknown
To subscribe / unsubscribe goto the site www.ilug-bom.org ., click on the mailing list
button and fill the appropriate information
and submit. For any other queries contact the ML maintener