Http://www.cnblogs.com/xinsheng/archive/2012/04/18/2455039.html
End Mode (Endian) is the word "Gulliver's Travels" written by Jonathan Swift. The book is based on the way the eggs are broken into two categories of people, from the beginning of the round the egg to open the person is classified as big Endian, starting from the tip of the egg to open the person is classified as Littile Endian (this sentence most image). The Civil war in the small country originates from the big-endian of the Big Head (or Little-endian) when eating eggs. In the computer industry big endian and little endian also almost caused a war. In the computer industry, endian represents the order in which data is stored in memory. The following examples illustrate the differences in the size-end mode in the computer.
If a 32-bit integer 0x12345678 is stored in an integer variable (int), this integer variable is stored in memory by the big-endian or small-end pattern, as shown in the following table. For simplicity, this article uses OP0 to represent the highest byte MSB (most significant byte) of a 32-bit data, using OP3 to represent a 32-bit data minimum byte LSB (Least significant byte).
Address offset |
Big-endian mode |
Small terminal mode |
0x00 |
(OP0) |
(OP3) |
0x01 |
(OP1) |
(OP2) |
0x02 |
(OP2) |
(OP1) |
0x03 |
(OP3) |
(OP0) |
Small end: A higher valid byte is stored at a higher memory address, and a lower valid byte is stored at a lower memory address.
Big-endian: a higher valid byte is stored at a lower memory address, and a lower valid byte is stored at a higher memory address.
If a 16-bit integer 0x1234 is stored in a short integer variable (shorter). This short integer variable is stored in memory in the size end pattern as shown in the following table.
Address offset |
Big-endian mode |
Small terminal mode |
0x00 |
(OP0) |
(OP1) |
0x01 |
(OP1) |
(OP0) |
As is known from the above table, the main difference between the data storage in the size mode is the byte order in which the big end is stored in the low address, and the small-ended method stores the high-level address. The use of big-endian data storage in line with human normal thinking, and the use of small-end method of data storage is conducive to computer processing. So far, the use of big-endian or small-end data storage, the merits of the pros and cons are inconclusive.
Some processor systems use a small-end approach for data storage, such as Intel's Pentium. Some processor systems use a big-endian approach for data storage, such as IBM Semiconductors and Freescale PowerPC processors. Not only for the processor, some peripheral design also has the use of big-endian or small-end data storage options.
Therefore, in a processor system, there may be a big-endian and small-end mode simultaneously exist phenomenon. This phenomenon for the system hardware and software design brings a big trouble, which requires the system design engineer, must deeply understand the big-endian and small-end mode differences. The difference between the big end and the small terminal mode is embodied in a processor register, instruction set, system bus and other levels.
"Using the function to determine whether the system is big Endian or Little Endian"
Returns true if the byte order is Big-endian;
Reverse is Little-endian, return false
BOOL Isbig_endian ()
{
unsigned short test = 0x1234;
if (* (unsigned char*) &test) = = 0x12)
return TRUE;
Else
return FALSE;
}//isbig_endian ()
Report:
The scale value of the size end is byte, that is, each byte is in the normal order, but byte is assembled into an int or a long, and each byte is placed in a different position.
Size-End mode detailed