In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what's the difference between big-end byte order and small-end byte order". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between big-end byte order and small-end byte order"!
Byte order
First of all, byte order is determined by the architecture of CPU and has nothing to do with the operating system or the compiler.
Byte order is the order in which bytes are arranged in memory.
There are two kinds of byte order:
Big-end byte order: the high-order byte comes first and the low-order byte comes after, in the same way that humans read and write numerical values. Small-end byte order: low-order bytes first, high-order bytes last.
Why can byte order be divided into big end and small end?
Data is generally stored in bytes in memory, but some data types are larger than 1 byte, for example, short occupies 2 bytes, int takes 4 bytes, and the bus width of the processor is generally 32 bits and 64 bits, that is, a read and write operation can read and write 4 bytes or 64 bytes of data at the same time.
These more than 1 byte of data, there is the problem of how to sort the bytes in memory, according to the different sorting methods, there is a difference between the big-end mode and the small-end mode.
How to distinguish between big end and small end
Addresses in memory are generally accessed from low to high (opposite to stack memory), as shown in the following figure:
Suppose you have a hexadecimal number: 0x1234, which uses two bytes to store, then 0x12 is the high-order byte (high data bit) and 0x34 is the low-order byte (low data bit).
If the low-order byte 0x34 is stored at the high address of memory, it is the big-end byte order. That is, the computer first stores 0x12, and then stores 0x34, which is arranged as 0x1234 in memory. In line with human reading habits.
If the low-order byte 0x34 is stored at the low address of memory, it is small-end byte order. That is, the computer first stores 0x34, and then stores 0x12, which is arranged as 0x3412 in memory.
Similarly, the big-end byte order and small-end byte order of 0x1234567 are written as follows:
How to judge the current byte order by programming
Principle: is to read a short variable or other type of face of the first byte of data, the first byte (low address, is also the starting address) of the data storage is the high-order byte data is the big end, on the contrary, if the first byte of the data store its own low-end data is the small end.
The code is as follows, and the current byte order can be judged after compiling and running.
# include int main () {short byteOrder = 0x1234; char cOrder = (char) & byteOrder; / / short the value of one byte (low address) stored in memory, assigned to char if (cOrder = = 0x12) {printf ("Big-Endian\ n");} else {printf ("Little-Endian\ n") } return 0;}
Byte order and CPU Architecture
Cpu:PowerPC of large-end mode (default big-end), IBM,SUN.
Cpu:x86,DEC in small-end mode.
Arm can work in either large-end mode or small-end mode.
Classification of cpu schemas
At present, the classification of CPU instruction sets on the market is mainly divided into two camps.
One is the complex instruction set CPU headed by intel and AMD.
The other is the reduced instruction set CPU headed by IBM and ARM.
Two different brands of CPU have different product architectures.
For example, CPU of Intel and AMD is X86 architecture, while CPU of IBM is PowerPC architecture and ARM is ARM architecture.
The CPU of x86 architecture is small-end byte order, the CPU of PowerPC architecture is big-end (default big-end), and the CPU of ARM architecture is small-end (default small-end).
Network byte order
Network byte order, the unified use of large-end byte order.
At this point, I believe you have a deeper understanding of "what is the difference between big-end byte order and small-end byte order". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.