Big and Small End (network byte order and host byte order)
Big endian: The network byte order.
Small end (Littile endian): the host byte order.
Memory mode: The scope of the network is very large, so the big-endian is the network byte order.
Big-end mode will be high stored in the low address, small side of the way will be placed low in high address.
The data storage in the big end is in accordance with the normal thinking of human being, and the data stored in the small port is beneficial to computer processing.
If a 32-bit integer 0x12345678 is stored in an integer variable (int), the integer variable is stored in memory in a big-end or small-ended mode as shown in the following table.
For simplicity, this book 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 End mode small port mode
0x00 (OP0) (OP3)
0x01 (OP1) (OP2)
0x02 (OP2) (OP1)
0X03 (OP3) (OP0)
You can test with the following code
int i=0x12345678;
Char*p = (char *) &i;
if (*p = = 0x78)
{
printf ("litle endian\n");
}
printf ("p=%p\n", &p);//The value of the current pointer variable (point to address)
p++;//the pointer from
printf ("p++, p=%p\n", &p);/ Verify that the value after the pointer has been increased (the *p address)
if (= = 0x56)
printf ("litle endian\n");
printf ("sizeof (p) =%lu \ n", sizeof (p));
Test the number of bytes in the pointer variable, in fact, on the Win32 platform, any type of pointer variable takes up 4 bytes.
P =null;