Processing of field and collation on suggestion

Source: Internet
Author: User
Tags web hosting

If you are planning to make a suggestion on a machine with a small collation, you need to pay attention to the topic of the collation.

This problem was encountered yesterday when I processed the IP address.

X86 refers to the small-End Word collation, while the Web Hosting refers to the large-End Word collation. The first four digits of the IP Address Sequence are the version sequence, and the last four digits are the sequence length. That is, version = 0x4 (IPv4 ), length = 0x5 (20 characters in length), and 0x45 occurs on the webpage. If we define a structure sta to capture:

Strruct sta

{

Unsigned char b4version: 4;

Unsigned char b4headlen: 4;

};

Func ()

{

...

Sta X;

Memcpy (& X, Buf, sizeof (x); // the pseudo-configuration Buf is an IP address text, and the first word is 0x45

...

}

So what is the difference between b4version and b4headlen?

Sorry, I'm sorry to tell you that the machine is in the small-end Character Sequence, b4version = 0x5, b4headlen = 0x4!

This structure allocates segments starting from low positions, that is, b4version uses 4 lower bits and b4headlen uses 4 Higher bits, however, 0x45 means that 0100 0101b is very clear, and 4 lower bits are 0101b = 5, and 4 Higher bits are 0100b = 4, so it is reversed.

 

Solution: Let me think about it...

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.