Binary files represent multibyte types, such as 32-bit int
s in a way that is often specific to the architecture on which they were generated. Although reading int
s from a binary file will produce the same numbers as were written to the file on the same machine, reading files produced by other machines may give you incorrect results.
It looks like the file that you are reading has been produced on a computer with the opposite endianness. If you plan to read these files only on your computer, you could write a simple function that swaps the byte order for you. If you plan to make binary files that are independent of architecture, you should pick one byte order (for example, the network order, also known as "big-endian") and then use byte reordering routines specific to your system.