Big and small study notes

Source: Internet
Author: User

Large-end encoding: the high bytes of word data are stored in the low address.
Small-end encoding: Low-byte storage of word dataIn the lower address.

Simply and intuitively,(Of course, this approach is not rigorous ).
After reading the next CSDN blog, I wrote it quite comprehensively. At the end of this article, I will give the relevant address, but the content is a bit too much. So I should write my study notes by myself. Although it is not new knowledge, it is always good to know new people for a warm time.

Here, allow me to extract the part I need:

Another problem is often encountered during interviews. Write a small program to determine whether the compiler is in the big-end or small-end mode (the large-end returns 0, and the small-end returns 1 ):

= (c.b == 

Every time I see this code, I think it is very painful, mainly because I have not understood it very deeply, so I provide another more intuitive and clear judgment method:

=  (c.b == 

Because all members in the consortium are stored from the low address, directly compare c. the values of B and 0x12 are the same. If the values are the same, it indicates that the format is large (1 is returned). If the values are different, it indicates that the format is small (0 is returned ).

 

How does the size end address come from?
In the operating system, data is stored in bytes. one byte type is 8 bits, the char short type is 16 bits, and the int float type is long (depending on the compiler) 32 bits and double bits. In this case, you need to differentiate the storage mode.
The int and long types depend on the platform and compiler. For example, to compile C or C ++ programs, sometimes considering cross-platform compatibility, We need to explicitly use _ int8, _ int16, _ int32, _ int64.

 


In fact, the operating system is generally a small-end, and Java and all network communication protocols are large-end, so when we perform network programming suchSocket programmingPay attention to this point, so we often need to use these functions to convert the byte order of the large and small ends (but I will only copy the settings when applying them, but I don't really understand them deeply ).
If you want to have a better understanding, you need to go through the books related to the computer operating system. The related knowledge in this area is too weak... the book "Modern Operating System" is good, and the book "writing an operating system by yourself" is also very good. When I hear my name, I am very friendly-I write it myself... Have the opportunity to read, read, and write.

 

For more information, see the following blog:

Details about big-end mode and small-end Mode

 

 

 

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.