3 ms·
Given that most CPUs are or can run in little-endian mode these days, why are so many new protocols and file formats using big-endian for storing numbers, like
by magicalhippo 5y ago
Given that most CPUs are or can run in little-endian mode these days, why are so many new protocols and file formats using big-endian for storing numbers, like record lengths etc?
- monocasa 5y ago'Network endian'. Not saying it's a great idea though.
- magicalhippo 5y agoSure, but why? For something that's on the application layer, why should network byte order dictate things?
- BlackFly 5y agoWhy should the ubiquity of a particular hardware design dictate that you diverge from the canonical representation of a number? If we were laying out digits and not bytes, everyone would find it bizarre to lay it out little endian, we all know the canonical layout of the digits of a number and changing that really requires some documentation. Why would changing radix change what is canonical? It gets really annoying when you convert from radix 16 to radix 2 and suddenly your "little endian" layout is actually mixed endian because rarely will people apply the endianness to representations of bits (of course, you already see mixed endianness in radix 16, it is only in radix 256 that little endianness exists and isn't actually mixed endian). So when people are choosing to write things to wire, big endian seems quite natural because what is natural in radix 10 is equally natural in radix 16 and equally natural in radix 2.
- magicalhippo 5y ago> Why should the ubiquity of a particular hardware design dictate that you diverge from the canonical representation of a number? Performance. Byte-swapping "everything" isn't free. And there's already precedence for it, after all most binary formats use multiples of 8 bits for the same reason when storing numbers etc.
- deleted 5y ago[deleted]
- Const-me 5y agoBecause people are lazy in general. It’s easier to follow what perceived to be a convention, without questioning these conventions. Programming books and university classes don’t update that frequently, the amount of old information creates that perception. I am only using big endian for variable-length integers: https://www.rfc-editor.org/rfc/rfc8794.html#name-variable-size-integer https://www.rfc-editor.org/rfc/rfc8794.html#name-variable-si... In that particular use case, allows to find length of the integer by only reading the first byte. This feature helps for use cases when you wanna skip fields instead of de-serializing them. And, it doesn’t screw up bit patterns. A variable-length integer 0x808080 gonna have three 0x80 bytes somewhere in the serialized stream. This feature sometimes helps debugging things. A little endian equivalent would have them bit-shifted by the size of header. For fixed-length integers, I only using little-endian in my file formats.