Last active
June 8, 2020 02:07
-
-
Save euccas/b70e786c83ed852aed465964c0ffdb82 to your computer and use it in GitHub Desktop.
Zlib function: bits reverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* =========================================================================== | |
* Reverse the first len bits of a code, using straightforward code (a faster | |
* method would use a table) | |
* IN assertion: 1 <= len <= 15 | |
*/ | |
local unsigned bi_reverse(code, len) | |
unsigned code; /* the value to invert */ | |
int len; /* its bit length */ | |
{ | |
register unsigned res = 0; | |
do { | |
res |= code & 1; | |
code >>= 1, res <<= 1; | |
} while (--len > 0); | |
return res >> 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment