From: | Alastair M. Robinson |
Date: | 22 Dec 99 at 22:00:12 |
Subject: | Counting bits in a long... revisited |
From: "Alastair M. Robinson" <blackfive@fakenhamweb.co.uk>
Hi All,
I read in the Aminet digests that someone was asking (ages and ages ago)
for a way of counting the number of bits in a longword. I came across
a really elegant way to do this in a fortune-cookie file (!), and it's *so*
cute I just had to share it with everyone!
int BitsInLong(unsigned long l)
{
l=((l>>1) & 0x55555555) + (l & 0x55555555);
l=((l>>2) & 0x33333333) + (l & 0x33333333);
l=((l>>4) & 0x0f0f0f0f) + (l & 0x0f0f0f0f);
l=((l>>8) & 0x00ff00ff) + (l & 0x00ff00ff);
return(((l>>16) & 0x0000ffff) + (l & 0x0000ffff));
}
Happy Christmas everyone!
Daddy, what does "FORMATTING DRIVE C:....." mean ?