Skip to content

Instantly share code, notes, and snippets.

@rickymanning
Last active June 7, 2016 11:00
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 rickymanning/660e9acf9504032b7feb9210917f1dd7 to your computer and use it in GitHub Desktop.
Save rickymanning/660e9acf9504032b7feb9210917f1dd7 to your computer and use it in GitHub Desktop.
The getbits() function in K&R (The C Programming Language, 2nd Edition)
/* getbits: get n bits from position p */
unsigned getbits(unsigned x, int p, int n)
{
return (x >> (p+1-n)) & ~(~0 << n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment