Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jlongster/562511 to your computer and use it in GitHub Desktop.
Save jlongster/562511 to your computer and use it in GitHub Desktop.
#define READ_BYTES(var, type) \
do { \
var = 0; \
type n; \
int count = sizeof(type); \
int last_bit = (count-1)*8; \
int i; \
\
fread(&n, sizeof(type), 1, f); \
\
for(i=0; i<=last_bit; i+=8) { \
int start = i; \
int end = last_bit - i; \
\
if(start < end) \
var |= (n & (0xff << start)) << (end - start); \
else \
var |= (n & (0xff << start)) >> (start - end); \
} \
} while(0); \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment