I am trying to parse the FAT filesystem & I notice that many of the fields are more than 2 bytes. I was reading someone's program and he has defined unsigned short for a given field of 2 bytes. Now, my question is how does the compiler handle endianness? If I convert the short into hex by using 02x, the data is handled properly. The file is opened in binary mode & I wonder how data more than a byte can be interpreted i.e. how does the compiler know which byte is the LSB/MSB? The same goes for long and int.

4 Years
Discussion Span
Last Post by rubberman

AFAIK, FAT file systems are all encoded in the format used by Intel x86 processors - LittleEndian. Use this to test:

#include <endian.h>
/* We have a LittleEndian machine - Intel most likely, but possibly an ARM or MIPS in LE configuration. */
/* We have a BigEndian machine - an old 68000 system perhaps? */
/* We have something else - probably an old PDP-11 */

This construct is commonly used in system-level programming.

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.