Little-Endian and big-Endian

Source: Internet
Author: User

This is a question about how to place bytes when data is stored in the bucket. This is related to the architecture of the PC used and the operating system.

What are common architectures, operating systems, and their use?

Generally, intel X86 uses little-Endian In the CPU architecture, while the cpu Of the Motorola series specifically uses big-Endian In the PowerPC series. arm supports both of them, but the default value is little-Endian. This is also true for Linux. Mac uses big-Endian.

C/C ++ is little-Endian, and Java is big-Endian. Therefore, data transmission between these two types must be converted.

What does little-Endian and big-Endian mean?

First, a number is used to distinguish the highest valid byte MSB. We can see the lowest valid byte LSB, for example, 0x12345678, the first 0x12... refers to MSB, And the last 0x... 78 refers to LSB.

Big endian stores MSB at a low address, while little endian stores LSB at a low address. To put it simply, big-Endian refers to a high-position low address, while little-Endian refers to a low-position low address.

Big-Endian refers to big end first, that is, putting a large number first, or putting a high-base number first.

If the base address is 0x1000, the data is placed

Address little-Endian big-Endian

0x1000 78 H 12 h

0x1001 56 H 34 h

0x1002 34 h 56 h

0x1003 12 h 78 h

Note that the smallest unit here is byte, so in big-Endian it looks like the order of printing, but even in little-Endian, it is not completely reversed, it is reversed by byte, so there will be no numbers such as a certain byte into 21h.

At the same time, the order here refers to the Sorting Problem in a word or DWORD, where a word is 16 bits and DWORD is 32-bit. For multi-byte data with more than one DWORD, it is still stored in order. For example, a 64-bit data value of 0x1122334455667788, the order in little-Endian is 0x44 0x33 0x22 0x11 0x88 0x77 0x66 0x55. (To be verified)

What is the historical source?

The word "endian" comes from Gulliver Travel Notes. The civil war in the minor people's country originated from the fact that the big-Endian attack or the little-Endian attack were triggered when the eggs were eaten. There were six rebels. The general reason is that traditionally it was opened by a big head, but a grandfather of a certain King hurt his finger when he opened the eggs according to the tradition. Therefore, the king ordered everyone to open the eggs with a small head, however, if someone does not agree, a rebellion occurs.

What are the advantages and disadvantages?

In little-Endian, the offset 0 is placed in byte0, which makes it clearer when the number is put, and it is easier for the assembly language to obtain the number.

Big-Endian is consistent with our printing order to facilitate binary and decimal conversion. At the same time, the highest bit is at the beginning, so it is easy to judge the positive and negative values of this number.

Pay attention to the format of special applications. For example, the BMP file is of little-Endian.

Common file formats and Their endian order are as follows:

  • Adobe Photoshop-- Big endian
  • BMP (Windows and OS/2 bitmaps)-- Little endian
  • DXF (AutoCAD)-- Variable
  • GIF-- Little endian
  • IMG (GEM raster)-- Big endian
  • JPEG-- Big endian
  • Fli (Autodesk animator)-- Little endian
  • Macpaint-- Big endian
  • PCX (PC paintbrush)-- Little endian
  • Postscript-- Not applicable (Text !)
  • POV (persistence of vision ray-tracer)-- Not applicable (Text !)
  • Qtm (QuickTime movies)-- Little endian (on a Mac !)
  • Microsoft riff (. wav &. AVI)-- Both
  • Microsoft RTF (Rich Text Format)-- Little endian
  • SGI (Silicon Graphics)-- Big endian
  • Sun raster-- Big endian
  • TGA (Targa)-- Little endian
  • Tiff-- Both, endian identifier encoded into File
  • WPG (WordPerfect Graphics Metafile)-- Big endian (on a PC !)
  • Xwd (X Window dump)-- Both, endian identifier encoded into File

Reference:

Http://en.wikipedia.org/wiki/Endianness

Http://www.cppblog.com/future0906/archive/2005/11/19/1193.html

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.