How to tell if your computer is big endian or small byte-order storage

Source: Internet
Author: User

In simple terms   The so-called big- endian storage is the high-order content of the low address, then the small-endian storage is the low-order content exists at the high address. (picture to do with explanation)


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7E/CE/wKiom1cI50nxpH7GAAAqkzvghIo428.png "title=" storage. png "alt=" Wkiom1ci50nxph7gaaaqkzvghio428.png "/>



In the computer, the data is in the form of the second complement is stored in the computer, the top of the big-endian storage and small pieces of storage, but each computer is not the same way of storage, then, how to determine whether a computer is interrupted storage or small pieces of storage it?!

Here's a single function to implement this function:

We know that 1 stored in the computer is 00000000 00000000 00000000 00000001 (complement), whose hexadecimal representation is FF FF FF, if the address is taken,

The computer is likely to display the following:———————— small End storage

Or:———————— big-endian storage

Therefore, when we know that the first bit of data storage after 1 can be judged that this computer is stored in the big-endian storage or small pieces of storage (of course, the numbers here can be given casually, but for the sake of convenience, choose 1)

int Sys_check () {int num = 1;char *p = (char *) #              if (*p = = 1) return 1;              Small end storage Elsereturn 0; Big-endian storage}int main () {int num = 1;int ret = Sys_check (); if (ret = = 1) {printf ("little\n");} else if (ret = = 0) {printf ("big\n");} System ("pause"); return 0;}


How to tell if your computer is big endian or small byte-order storage

Related Article

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.