Size mode of Linux system

  
 

Big End Mode

The so-called big endian mode means that the lower bits of the data (that is, the latter bits with smaller weights) are stored in the high address of the memory, and the high bits of the data are stored in In the low address of memory, such a storage mode is somewhat similar to processing data as a string: the address is increased from small to large, and the data is placed from high to low;

Little Endian

The so-called little endian mode means that the lower bits of data are stored in the lower address of the memory, and the upper bits of the data are stored in the upper address of the memory. This storage mode effectively combines the address level and the data bit weight. The high address part has a high weight and the low address part has a low weight, which is consistent with our logical method.

Why is there a big endian mode?

Why is there a big endian mode? This is because in a computer system, we are in bytes, each address unit corresponds to one byte, and one byte is 8 bits. However, in addition to the 8-bit char in the C language, there are 16-bit short type, 32-bit long type (depending on the specific compiler), and, for the processor with more than 8 bits, for example, 16-bit or 32-bit. The processor, since the register width is larger than one byte, there must be a problem of how to arrange multiple bytes. As a result, the big endian storage mode and the little endian storage mode are caused. For example, a 16-bit short type x, the address in memory is 0x0010, and the value of x is 0x1122, then 0x11 is the high byte and 0x22 is the low byte. For big endian mode, put 0x11 in the low address, ie 0x0010, and 0x22 in the high address, ie 0x0011. Little endian mode, just the opposite. Our commonly used X86 architecture is the little endian mode, while the KEIL C51 is the big endian mode. Many ARM and DSP are in little endian mode. Some ARM processors can also be selected by hardware to be big endian or little endian.

Test:

#include <stdio.h>

#include <sys/types>

main()

{

int x=0x12345678; /* 305419896 */

unsigned char *p=(char *)&x;

printf("%0x % 0x %0x %0x",xp[0],xp[1],xp[2],xp[3]);

}

Output: 78 56 34 12

Description is little end! The other way around is big endian

Copyright © Windows knowledge All Rights Reserved