How to confirm whether a computer is Big-endian or Little-endian?

Source: Internet
Author: User

Let's say we're using a 32-bit machine.

If it's little endian, then X is arranged in memory.

      High memory       ---->  +----+----+----+----+  |0x01|0x00|0x00|0x00|  +----+----+----+----+  A  |  &x SO (char*) (*x) = = 1


If it's big endian, it's going to be like this.

      High memory       ---->  +----+----+----+----+  |0x00|0x00|0x00|0x01|  +----+----+----+----+  A  |  &x SO (char*) (*x) = = 0


#include <stdio.h> #include <stdint.h>int is_big_endian (void) {union {uint32_t I;char c[4];} e = {0x10000000} ; return e.c[0];} int main (void) {printf ("System is%s-endian.\n", Is_big_endian ()? "Big": "little"); return 0;}


How to confirm whether a computer is Big-endian or Little-endian?

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.