Test platform big or small end (network byte order and host byte order)

Source: Internet
Author: User

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;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.