Determine whether the computer is a big or small end

Source: Internet
Author: User
Introduced

Computers have little endian (small end) and big endian, two pictures stolen from Wikipedia to illustrate their differences:

For 32-bit integers, the big-endian machines are high in memory low address storage, low in high address storage.

Small-end machines on the contrary, memory low address storage low, high address storage high.

Big-end notation and intuitive comparison of people, from the low address to the high address to see the past, is the original number; The small terminal notation is more convenient for computer operation, and the increase of address and Chivan is consistent.

How to judge your computer is little endian or big endian it. Intel's machines are basically little endian, or they can run simple code judgments. method One:

Python-c "Import sys; Print (Sys.byteorder) "

Terminal to run the above code, my laptop output little is a small-end machine. Method Two:

Write a simple C program, the following is copied from the Nginx source:

#include <stdio.h>
int main () {
    int i = 0x11223344;
    char *p;

    p = (char *) &i;
    if (*p = = 0x44) {
        printf ("Little endian\n");
    }
    else {
        printf ("Big endian\n");
    }
    return 0;
}

And then you run it:

GCC test.c &&/a.out
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.