当前位置:网站首页>The difference between big-endian and little-endian storage is easy to understand at a glance

The difference between big-endian and little-endian storage is easy to understand at a glance

2022-08-09 08:40:00 running little rabbit

Byte ordering is divided into big endian and little endian, the concepts are as follows

Big endian: The low address stores the most significant bytes.The first byte of data is stored first.

little endian: low address stores the least significant byte

stm32 is a little-endian mode, such as a 32-bit unsigned number 0x12345678,

Store 78h 56h 34h 12h sequentially from low address to high address.

1. Method and judgment of big endian and little endian


LSB means: full nameIt is the Least Significant Bit, which means the least significant bit in the binary number. Generally speaking, the MSB is located at the far left of the binary number, and the LSB is located at the far right of the binary number.

MSB means: the full name is Most Significant Bit, which belongs to the most significant bit in binary numbers, and MSB is the highest weighted bit, similar to the leftmost bit in decimal numbers.

0x12345678 Hexadecimal, two numbers are one byte The first byte of the data is 12 (MSB)

High significant byte --> Low significant byte: 12 34 56 78

Low address bits High and low address bits

Big endian: 12 34 56 78

Little Endian: 78 56 34 12

#includeint main(void ){unsigned int x =0x12345678;unsigned char *p = (unsigned char *)&x;printf("%0x %0x %0x %0x",p[0],p[1],p[2],p[3]);return 0;}

原网站

版权声明
本文为[running little rabbit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090833523818.html