MATLAB中fopen的“ieee-be”和“ieee-le”
(2013-03-03 19:50:46)ieee-be : big endian
ieee-le : little endian
Microprocessors support big-endian and little-endian byte ordering. Big-endian is an order in which the "big end" (most significant byte) is stored first (at the lowest address). Little-endian is an order in which the "little end" (least significant byte) is stored first.
The table below shows the representation of the hexadecimal number 0x0AC0FFEE on a big-endian and little-endian machine. The contents of memory locations 0x1000 to 0x1003 are shown.
0x10000x10010x10020x1003Big-endian0x0A0xC00xFF0xEELittle-endian0xEE0xFF0xC00x0A Why Different Byte Ordering?This is a difficult question. There is no logical reason why different microprocessor vendors decided to use different ordering schemes. Most of the reasons are historical. For example, Intel processors have traditionally been little-endian. Motorola processors have always been big-endian.
The situation is actually quite similar to that of Lilliputians in Gulliver's Travels. Lilliputians were divided into two groups based on the end from which the egg should be broken. The big-endians preferred to break their eggs from the larger end. The little-endians broke their eggs from the smaller end.
Conversion RoutinesRoutines to convert between big-endian and little-endian formats are actually quite straight forward. The routines shown below will convert from both ways, i.e. big-endian to little-endian and back.
Big-endian to Little-endian conversion and backshort convert_short(short in){ short out; char
*p_in = (char *) ∈ char *p_out = (char *)
&out; p_out[0] = p_in[1]; p_out[1] = p_in[0]; return
out;}long convert_long(long in){ long out; char *p_in = (char *)
∈ char *p_out = (char *) &out; p_out[0]
= p_in[3]; p_out[1] = p_in[2]; p_out[2] = p_in[1]; p_out[3] =
p_in[0]; return out;}
粘贴源:
http://www.eventhelix.com/RealtimeMantra/ByteAlignmentAndOrdering

加载中…