A program to determine whether the CPU is a big or small end

Source: Internet
Author: User

The byte order of the CPU is divided into big-endian mode and small-end mode.

Big-endian: The low byte of a data word is stored to the high address, and the high byte is stored in the low byte.

Small end opposite. It is advisable to remember only one, lest confusion be remembered.

1          BOOLcheckcpuislittleend ()2         { 3 Union W4             {5                 intA;6                 Charb;7             };8W.A =1;9             if(w.b = =1)Ten                 return true;//Small terminal mode One             return false; A}

When I looked at the code, the only question was: When I get a variable of char type, should I get it from the high address or low? The results are not yet found, but the output from the other blog's programs might infer that a variable that gets a char type is a value obtained from a low-byte address of the Union type. Thus, we can infer the following: If the value of W.B is 1, the low-byte address is 1 and the low-byte data is stored in a low-byte address. That is, the small-end mode. Otherwise, the big-endian mode.

A program to determine whether the CPU is a big or small end

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.