3 ms·
When 0x12345678 is stored in little endian, it looks like 78 56 34 12 in a byte dump, which is stupid because hex digits are grouped as pairs and then revered.
by kazinator 9y ago
When 0x12345678 is stored in little endian, it looks like 78 56 34 12 in a byte dump, which is stupid because hex digits are grouped as pairs and then revered.
The endianness at the bit level is irrelevant because the bits are chunked into bytes, and are usually not even addressable.
A storage format exhibits endianness only when it is addressable.
In the C language, bits are only "addressable" via the shift operators. These are rooted in pure arithmetic, so that 1<<1 is always 2, regardless of whether you're on a big or little endian platform. Whether you call the value 1 "bit 7", "bit 8", "bit 1" or "bit 0" is just, pardon the pun, word semantics.
The only time you deal with "bit endianness" is with certain compressed data formats, and with bitfield layout rules.
- tetrep 9y ago> Whether you call the value 1 "bit 7", "bit 8", "bit 1" or "bit 0" is just, pardon the pun, word semantics. It's extremely important to your mental model to understand how the bits are arranged, or left shift (<<) is going to produce different results in your head. If you think the value 1 is bit 7/8, you get: 1 0 0 0 0 0 0 0 Which would left shift to: 0 0 0 0 0 0 0 0 Which would not be equal to 2.
- kazinator 9y ago> It's extremely important to your mental model to understand how the bits are arranged And the shortcut for that is simply regard bytes as big-endian. On all platforms. Whether you're on a PPC or x86, the byte 0x80 is going to go out on the wire as 1 first, followed by 7 zeros. So if you're writing a data compressor and the spec says that the variable-length bit strings (huffman or whatever) are stuffed into bytes in network order, that means you fill bytes from the left down. That is done with code that works the same way on BE or LE platforms.