What is the big and small endian, why are there big and small endian, how to detect whether it is big endian or little endian

What is the big and small end

Big-endian mode: means that the high byte of data is stored at the low address of the memory, and the low byte of data is stored at the high address end of the memory.
Little-endian mode means that the high byte of data is stored in the high address of the memory, and the low byte is stored in the low address of the memory.

Why it appears:

The unit of computer allocation of memory is bytes, but an int or short has multiple bytes, naturally there are two ways that the high byte should have a high address or a low address

Detection method:

Directly read the hexadecimal value stored in the memory, and take the lower bit for value judgment

int a = 0x12345678;
int *c = &a;
c[0] == 0x12   大端模式
c[0] == 0x78   小段模式

Guess you like

Origin blog.csdn.net/qq_41634872/article/details/110139476