1. The large-end mode stores low data points in the high address of the memory, while the high data points are stored in the low address of the memory. The opposite is true for the small-end mode.
2. Why are there big and small ends ???
In computer systems, storage is in bytes. Each address unit corresponds to one byte, with a byte equal to 8 bits. In C language, apart from 8-bit char, there are 16-bit short type and 32-bit long type (depending on the specific compiler ). For a processor whose digits are greater than 8 bits, such as a 16-bit or 32-bit processor, how to arrange storage of multiple bytes because the register width is greater than one byte, this comes with the big-end storage mode and small-end storage mode.
3. respective advantages:
Small-end mode: you do not need to adjust the byte content for forced conversion of data. The storage methods of 1, 2, and 4 bytes are the same.
Large-end mode: the determination of the symbol bit is fixed to the first byte, and it is easy to judge positive and negative.
4. the commonly used X86 structure is the small-end mode, while the KEIL C51 mode is the large-end mode. Many ARM and DSP are in small-end mode.
5. c language to determine the size-end Mode
Method 1:
Copy codeThe Code is as follows: void IsBigEndian ()
{
Short int a = 0x1122; // hexadecimal, a value occupies 4 digits
Char B = * (char *) & a; // convert the short (2 bytes) type to a single char byte, and B points to the starting byte of a (low byte)
If (B = 0x11) // The low byte stores the high byte data of the data.
{
// Large-end Mode
}
Else
{
// Small-end Mode
}
}
Method 2:
Copy codeThe Code is as follows: void IsBigEndian () // principle: the order in which union members are stored is that all members are stored from the low address, and all Members share the bucket.
{
Union temp
{
Short int;
Char B;
} Temp;
Temp. a = 0x1234;
If (temp. B = 0x12) // low bytes store high bytes of data.
{
// Large-end Mode
}
Else
{
// Small-end Mode
}
}
I verified on my machine that it was a small-end mode.