Skip to content

Instantly share code, notes, and snippets.

@davidreynolds
Created June 30, 2012 20:36
Show Gist options
  • Save davidreynolds/3025419 to your computer and use it in GitHub Desktop.
Save davidreynolds/3025419 to your computer and use it in GitHub Desktop.
int getbit(int n) /* get n bits */
{
int i, x;
static int buf, mask = 0;
x = 0;
for (i = 0; i < n; i++) {
if (mask == 0) {
if ((buf = fgetc(infile)) == EOF) return EOF;
mask = 128;
}
x <<= 1;
if (buf & mask) x++;
mask >>= 1;
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment