Also recommending octal is sadistic!
Also recommending octal is sadistic!
There is a non-trivial chance that you will have to deal with BE data regardless if your machine is LE or BE.
Pretty low-key way to refer to pretty much all layer 1-3 IETF protocols :D
Apparently they designed it that way in order to ensure all values in the ELF are naturally encoded in memory when it is processed on the architecture it is intended to run on. So if you're writing a program loader or something you can just directly read the integers out of the ELF's data structures and call it a day.
Processing arbitrary ELF inputs requires adapting to their endianness though.
Back in the late 1990s, we moved from Motorola 68k / sbus to Power/PCI. To make the transition easy, we kept using big endian for the CPU. However, all available networking chips only supported PCI / little endian at this point. For DMA descriptor addresses and chip registers, one had to remember to use little endian.
It's not clear how it would free you from interpreting BE data from incoming streams/blobs.
If some legacy system still serializes big endian data then call bswap and call it a day.
I believe this dates from Bolt Baranek and Newman basing the IMP on a BE architecture. Similarly computers tend to be LE these days because that's what the "winning" PC architecture (x86) uses.
I'm not sure this is true. And if it is true it really shouldn't be. There are effectively no modern big endian CPUs. If designing a new protocol there is, afaict, zero benefit to serializing anything as big endian.
It's unfortunate that TCP headers and networking are big endian. It's a historical artifact.
Converting data to/from BE is a waste. I've designed and implemented a variety of simple communication protocols. They all define the wire format to be LE. Works great, zero issues, zero regrets.
POWER9, Power10 and s390x/Telum/etc. all say hi. The first two in particular have a little endian mode and most Linuces run them little, but they all can run big, and on z/OS, AIX and IBM i, must do so.
I imagine you'll say effectively no one cares about them, but they do exist, are used in shipping systems you can buy today, and are fully supported.
Almost no code anyone here will write will run on those chips. It’s not something almost any programmer needs to worry about. And those that do can easily add support where it’s necessary.
The point is that big endian is an extreme outlier.
There are vestiges of big-endian in the lower layers of the network but that is a historical artifact from when many UNIX servers were big-endian. It makes no sense to do new development with big-endian formats, and in practice it has become quite rare as one would reasonably expect.
For your own protocols there's no need to deal with big endian though.
I’m pretty sure there are examples that are way less niche though but I don’t want to look into it at the moment
The CPU is technically bi-endian but it’s controlled by a pin and it’s hardwired to big endian mode
Most C code just works, sometimes there are endianness bugs when porting things but they’re usually not hard to fix
(but mostly, network byte order is big endian)