Big end, Small End
I always thought that I had a clear understanding of the differences between the big end and small end. I did not expect that I would still be confused in practical applications. Here I will record that the same mistake cannot be made again.
Uint32_t temp = 0x01020304;
Big end: the & temp address stores high bytes (uint8_t *) & temp) [0] = 0x01;
Small End: The & temp address stores low bytes, that is, (uint8_t *) & temp) [0] = 0x04;
Remember
What is the difference between the big-end storage method and the Small-end storage method?
The large-end mode stores low-end data on the high address. High positions are stored on the address.
The small-end mode stores the status on the low-end address. High positions are stored on high addresses.
For example, the storage method of 16-bit 0x1234 in Little-endian mode CPU memory (assuming that it starts from address 0x4000) is:
Memory Address 0x4000 0x4001
Storage content 0x34 0x12
In Big-endian mode, the CPU memory is stored as follows:
Memory Address 0x4000 0x4001
Storage content 0x12 0x34
Why can this function determine the big end and small end:
Yes. In 32-bit systems, int occupies 32 bits and char occupies 8 bits.
78 indicates small-end data, and 12 indicates large-end data.