Live data from Hacker News

The Byte Order Fiasco

justine.lol

11–20 of 378 posts

Re: The Byte Order Fiasco

#11

This problem is it’s own special horror in Canbus data. Between endianness and sign it’s a nightmare of en/decoding possibilities and the associated mistakes that come with that.

TIFF is another one. The only endian-switchable image format that I'm aware of.

Fun fact: CD-ROM superblocks have both-endian fields. Each integer is stored twice in big and little endian format. I assume this was to allow underpowered 80s hardware which didn't have enough resource to do byte swapping.

Re: The Byte Order Fiasco

#12
post #3

Byte order is one of the great unnecessary historical fuck ups in computing. A similar one is that signedness of char is machine dependent. It's typically signed on Intel and unsigned on ARM. Sigh!

The good thing is that Big Endian is pretty much irrelevant these days. Of all the historically Big Endian architectures, s390x is indeed the only one left that has not switched to little endian.

Network protocols still mostly use "Network Byte Order", i.e. big endian.

Re: The Byte Order Fiasco

#13
post #3

Byte order is one of the great unnecessary historical fuck ups in computing. A similar one is that signedness of char is machine dependent. It's typically signed on Intel and unsigned on ARM. Sigh!

The good thing is that Big Endian is pretty much irrelevant these days. Of all the historically Big Endian architectures, s390x is indeed the only one left that has not switched to little endian.

Network byte order is big endian so it is far from being pretty much irrelevant these days.

Re: The Byte Order Fiasco

#14
post #8

If you can assume GCC or Clang then __builtin_bswap{16,32,64} functions are provided which will be considerably more efficient, less error-prone, and easier to use than anything you can homebrew.

_byteswap_{ushort,ulong,uint64} for MSVC. Together with yours on x86 these should take care of the three major compilers.

Re: The Byte Order Fiasco

#15
Remember how we used to have machines with a 7 bit byte? And everything was written to handle either 6, 7, or 8 bit bytes?

And now we've settled on all machines being 8 bit bytes, and programmers no longer have to worry about such details?

Is it time to do the same for big endian machines? Is it time to accept that all machines that matter are little endian, and the extra effort keeping everything portable to big endian is no longer worth the mental effort?

Re: The Byte Order Fiasco

#16

Remember how we used to have machines with a 7 bit byte? And everything was written to handle either 6, 7, or 8 bit bytes? And now we've settled on all machines being 8 bit bytes, and programmers no longer have to worry about such details? Is it time to do the same for big endian machines? Is it time to accept that all machines that matter are little endian, and the extra effort keeping everything portable to big end…

What happens is that all machines that matter are little endian but network works always in Big Endian.

Re: The Byte Order Fiasco

#17

Remember how we used to have machines with a 7 bit byte? And everything was written to handle either 6, 7, or 8 bit bytes? And now we've settled on all machines being 8 bit bytes, and programmers no longer have to worry about such details? Is it time to do the same for big endian machines? Is it time to accept that all machines that matter are little endian, and the extra effort keeping everything portable to big end…

IBM is going to be pretty annoyed when your code doesn't work on their mainframes.

Re: The Byte Order Fiasco

#19
post #8

If you can assume GCC or Clang then __builtin_bswap{16,32,64} functions are provided which will be considerably more efficient, less error-prone, and easier to use than anything you can homebrew.

That's not true. If you write the byte swap in ANSI C using the gigantic mask+shift expression it'll optimize down to the bswap instruction under both GCC and Clang, as the blog post points out.

Re: The Byte Order Fiasco

#20
post #3

Byte order is one of the great unnecessary historical fuck ups in computing. A similar one is that signedness of char is machine dependent. It's typically signed on Intel and unsigned on ARM. Sigh!

By the way, mathematicians also have their fuck ups:

https://tauday.com/tau-manifesto

Post reply on HN