Bigendian Vs Littleendian
Anyone know of a way to tell if a compiler you are using is big or little ended ?
I am reading a lump of data into a structure, and have finally figured out that it''s all stored in reverse to what is in the file. (if I do fs.read(..))
if I do fs>>var1, then fs>>var2 etc, all the data is read in correctly, but each variable is in reverse to what I would expect from looking at the file.
Any comments ?
Bp.
int a = 1;if(*(char*)&a) little_endian = true;
If you''re on a little endian system, and reading big endian (aka network byte order) data, use ntoh?.
You can also read byte for byte, constructing the number yourself:
static inline u32 read32(const u8* p){ u32 t = 0; for(int i = 0; i < 32; i += 8) t |= (*p++) << i; return t;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement