Skip to content

Instantly share code, notes, and snippets.

@euccas
Last active June 8, 2020 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euccas/b70e786c83ed852aed465964c0ffdb82 to your computer and use it in GitHub Desktop.
Save euccas/b70e786c83ed852aed465964c0ffdb82 to your computer and use it in GitHub Desktop.
Zlib function: bits reverse
/* ===========================================================================
* 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