The difference between Big endian and little endian

Source: Internet
Author: User

Author:skate
Time:2010/03/05

1. What is big Endian and little Endian.

There are two ways to work with data in memory when designing a computer system. A value called Little-endian, which is stored in the lowest bit in memory, is derived from the data
The rightmost part (the lowest bit of the data). For example, a 16 binary digital 0x12345678, in memory storage in the following way:

Low address------------------> High address
####################################################
Value #0111, #0101, 0110 # 0011,0100 # 0001,0010 #
####################################################
Address # 100 # 101 # 102 # 103 #
####################################################

The other is called Big-endian, in contrast, the value of the lowest bit in memory is from the leftmost portion of the data (that is, the highest part of the data).
For example, a 16 binary digital 0x12345678, in memory storage in the following way:


Low address------------------> High address
####################################################
Value # 0001,0010 #0011, 0100 # 0101,0110 # 0111,1000 #
####################################################
Address # 100 # 101 # 102 # 103 #
####################################################


As can be seen from the above example, the big endian way to store data is in line with our human thinking habits.


Big endian: Refers to the low address holds the most significant byte (Msb:most significant byte, the most significant byte),
Little endian: The low address holds the lowest valid byte (lsb:least significant byte, the least significant byte)


When it comes to the problem of byte order, it is bound to involve two CPU factions. That's Motorola's PowerPC series CPU and Intel's x86 series CPUs.
IBM, Motorola (Power PC), Sun's machines typically use big endian to store data. And the x86 series uses
Little endian way to store data

Little endian or big endian are related to the operating system and chip type. Refer to the processor manual for specific scenarios.

2. How to tell if the system is big Endian or little Endian

Find the string Byte_order (or _byte_order, __byte_order) in/usr/include/(including subdirectories) to determine its value.
This value is typically found in endian.h or machine/endian.h files, and sometimes in feature.h, different operating systems may
Different. In general, the Little endian system Byte_order (or _byte_order,__byte_order) is a 1234,big endian system of 4321


3. Why pay attention to the problem of byte order.

In a single-machine environment, the program does not take into account the problem of byte order (endian), because the different byte order is in different standalone environment, if you want to be in a different stand-alone
To pass data between, consider the problem of byte order, because the data is accessed by address, if you are different byte-order single-machine communication, will cause the transfer of data
"Mutation", for example, passes the pointer of the data 0x12345678 of the little endian environment to the big endian environment, and the data is "mutated" to 0x78563412

All network protocols also use big endian to transfer data. So sometimes we also call the big endian way the network byte order. When two units are mined
When a host communicates with a different byte sequence, it must be transformed into a network byte order before transmitting the data before it is transmitted.

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.