pea
developer
Hi all,
I am stepping through arbitrary byte data with a char* pointer (as you do ) and at some stage I have to read a 'long' or 'unsigned long' data type.
Usually, you could just go:
Which works perfectly, UNLESS the pointer fpt does NOT happen to be on a 4-byte boundary. It just crashes the GP. So I tried this:
But it just comes up with some crazy number. Maybe I am not taking the sign into account? Or maybe the byte order is wrong?
How can I read a long or unsigned long from a byte pointer which is not on a four-byte boundary?
I am stepping through arbitrary byte data with a char* pointer (as you do ) and at some stage I have to read a 'long' or 'unsigned long' data type.
Usually, you could just go:
Code:
unsigned char *fpt;
// Read some bytes etc
byte1 = *fpt; fpt++;
byte2 = *fpt; fpt++;
// Read an unsigned long
ulong1 = *((unsigned long*)fpt);
Which works perfectly, UNLESS the pointer fpt does NOT happen to be on a 4-byte boundary. It just crashes the GP. So I tried this:
Code:
ulong1 = *(fpt+0)<<24 + *(fpt+1)<<16 + *(fpt+2)<<8 + *(fpt+3);
How can I read a long or unsigned long from a byte pointer which is not on a four-byte boundary?