Add C code that counts the bits in a 32 bit word, right next to the C code

that reverses the bits in a 32 bit word.  Who thinks up this stuff?
This commit is contained in:
Peter Wemm 2002-07-09 02:56:10 +00:00
parent 7da9dccb66
commit 518b7839f2
2 changed files with 15 additions and 0 deletions

View File

@ -1416,6 +1416,14 @@ music at top volume and at least a pint of ether.
n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
-- C code which reverses the bits in a word.
%
n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1);
n = (n & 0x33333333) + ((n & 0xcccccccc) >> 2);
n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >> 4);
n = (n & 0x00ff00ff) + ((n & 0xff00ff00) >> 8);
n = (n & 0x0000ffff) + ((n & 0xffff0000) >> 16);
-- C code which counts the bits in a word.
%
" ... I told my doctor I got all the exercise I needed being a
pallbearer for all my friends who run and do exercises!"

View File

@ -2706,6 +2706,13 @@ audience, either."
n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
-- Reverse the bits in a word.
%
n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1);
n = (n & 0x33333333) + ((n & 0xcccccccc) >> 2);
n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >> 4);
n = (n & 0x00ff00ff) + ((n & 0xff00ff00) >> 8);
n = (n & 0x0000ffff) + ((n & 0xffff0000) >> 16);
-- Count the bits in a word.
%
Never ask your lover if he'd dive in front of an oncoming train for
you. He doesn't know. Never ask your lover if she'd dive in front of an