For a 16-bit integer consisting of 2 bytes, there are two ways to store these two bytes in memory: One is to store the low-order bytes at the start address, which is called the small-end (Little-endian) byte order, and the other is to store the high-order bytes at the start address, which is called the big-endian (Big-endian ) byte order. The term "small end" and "big endian" indicate which end (small or big) of multiple byte values is stored at the starting address of the value.
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
int main ()
{
Union
{
Short S;
Char c[sizeof (short)];
} un;
UN.S = 0x0102;
if (sizeof (short) = = 2)
{
if (un.c[0] = = 1 && un.c[1] = = 2)
printf ("big-endian\n");
else if (un.c[0] = = 2 && un.c[1] = = 1)
printf ("little-endian\n");
Else
printf ("unknown\n");
}
Else
printf ("sizeof (short) =%d\n", sizeof (short));
Exit (0);
System ("pause");
}
The above is a detection of small end of the program.
The concept of the small end of big endian