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:
parent
7da9dccb66
commit
518b7839f2
@ -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!"
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user