Created
September 2, 2010 16:29
-
-
Save jlongster/562511 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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