[CLUE-Tech] Byte Order

gary.l.shapiro at lmco.com gary.l.shapiro at lmco.com
Wed Dec 20 09:52:24 MST 2000


I just started using a Linux computer for the first time, and I've already noticed a peculiar phenomenon. We have some code which was designed to be portable: it works on both PC (Windows) and Unix platforms. To do this, the code performs a "check" on the byte order, which consists of placing a short constant (1) in memory, then examining the first byte. If the byte is 1, the machine is LittleEndian, if 0, the machine is BigEndian. Of course, the Linux machine, being an Intel, is LittleEndian. When the data is written to a binary file using fwrite, however, it writes it in BigEndian order. Is this normal for Linux? Of course, the data is "marked" as LittleEndian, even though it is written as BigEndian, which creates problems when I read in the data for another program. The obvious solution is to override the byte check when using Linux. If this is standard Linux behavior, what indicator can I use to do this and still keep the current behavior on Windows and Unix platforms?

Gary Shapiro
Software Engineer
Advanced Processing Group
Lockheed Martin Space Systems / Astronautics Operations
Denver, CO



More information about the clue-tech mailing list