search
HomeCommon ProblemWhat is the difference between big endian mode and little endian mode?

Difference: In big-endian mode, the high byte of word data is stored in the low address, and the low byte of word data is stored in the high address; contrary to the big-endian storage mode, in the little-endian storage mode In the low address, the low byte of word data is stored, and the high address stores the high byte of word data.

What is the difference between big endian mode and little endian mode?

#The operating environment of this article: Windows 7 system, Dell G3 computer.

Related recommendations: "Introduction to Programming"

The difference between big endian mode and little endian mode

In addition to the 8-bit char type in C language, there are also 16-bit short type and 32-bit long type (depending on the specific compiler). For processors with more than 8 bits, such as 16-bit Or for a 32-bit processor, since the register width is larger than one byte, there must be a problem of how to arrange multiple bytes. This leads to big-endian storage mode and little-endian storage mode.

Big endian mode:

The high byte of word data is stored in the low address, while the low byte of word data is stored in the high address.

Little endian mode:

Contrary to the big endian storage mode, in the little endian storage mode, the low byte of the word data is stored in the low address, and the high byte of the word data is stored in the low address. The address stores the high byte of word data.

For example, the way the 16-bit wide number 0x1234 is stored in the little-endian mode CPU memory (assuming it is stored starting from address 0x4000) is:

Memory address

0x4000

0x4001

Storage content

0x34

0x12

And in big endian mode CPU The storage method in the memory is:

Memory address

0x4000

0x4001

Storage content

0x12

0x34

The storage method in big-endian mode CPU memory is:

Memory address

0x4000

0x4001

0x4002

0x4003

Storage content

0x12

0x34

0x56

0x78

The X86 structure we commonly use is Little endian mode, while KEIL C51 is big endian mode. Many ARM and DSP are in little-endian mode. Some ARM processors can also select big-endian or little-endian mode by hardware.

Note: Using the big-endian method to store data is in line with normal human thinking, while using the little-endian method to store data is conducive to computer processing.

(My understanding: little endian mode puts a low bit in the low byte)

The following code can be used to test whether your compiler is in big endian mode or Little endian mode:

int main()
{
short int x;
char x0,x1;
x=0x1122;
x0=*((char*)&x); //低地址单元 ,或者((char*)&x)[0];
x1=*((char*)&x + 1); //高地址单元,或者((char*)&x)[1];
printf("x0=%x\nx1=%x\n",x0,x1);
}

If x0=0x11, it is big endian; if x0=0x22, it is little endian....

Want to read more related For articles, please visit PHP中文网! !

The above is the detailed content of What is the difference between big endian mode and little endian mode?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.