←back to thread

27 points andwati | 2 comments | | HN request time: 0s | source
Show context
MrBuddyCasino ◴[] No.45905428[source]
What first confused me about endianness is that it is about byte order, not bit order. The latter would have seemed more logical, or is this just me?
replies(5): >>45905811 #>>45906279 #>>45906495 #>>45907705 #>>45907834 #
1. cobbal ◴[] No.45906279[source]
Little endian does appear strange at first, but if you consider the motivation it makes a lot of sense.

Little endian's most valuable property is that an integer stored at an address has common layout no matter the width of the integer. If I store an i32 at 0x100, and then load an i16 at 0x100, that's the same as casting (with wrapping) an i32 to an i16 because the "ones digit" (more accurately the "ones byte") is stored at the same place for both integers.

Since bits aren't addressable, they don't really have an order in memory. The only way to access bits is by loading them into a register, and registers don't meaningfully have an endianness.

replies(1): >>45908034 #
2. IshKebab ◴[] No.45908034[source]
I'm not sure I've ever seen that actually come in to play. Little Endian is obviously the best Endian, but I don't think that argument really makes sense.

The most obvious argument is that little Endian is clearly the most natural order - the only reason to use Big Endian is to match the stupid human history of mixing LTR text with RTL numbers.

I've seen one real technical reason to prefer little endian (can't remember what it was tbh but it was fairly niche) and I've never seen any technical reasons to prefer big endian ("it's easier to read in a hex editor" doesn't count).