I'm coding a C program to read and parse a BMP header. The first 2 characters are chars, which I'm printing fine. However, all the other bits are ints in little endian format, so I'm storing them backwards. In hex, I'm getting the right answer. However, when I try to cast them to an int (for readability), I get an invalid number.
bmp.c --
printf("file size: "%02x %02x %02x %02x\n", bmp->size[0], bmp->size[1], bmp->size[2], bmp->size[3]);
printf("file size: "%d\n", bit2int(bmp->size));
bit2int function --
int bit2int(void *thing)
{
return *(int*)thing;
}
output -- (actual file size is 415,798 bytes)
file size: 00 06 58 36
file size: 911738368
edit 1 -- Function I'm currently using
void storebackwards(void *dst, void *src, int offset, int n) {
for(int i = n; i > 0; i--)
memcpy( dst + n - i, src + offset + i - 1, 1);
}