News for hackers. Stuff that matters.
Re:Big-Endian Testing with QEMU by GandalfHN on Friday April 03, 2026 @12:13PM (#47628507)
Outsourcing endianness pain to your customers is an easy way to teach them about segfaults and silent data corruption. s390x is niche, endian bugs are not.

Network protocols and file formats still need a defined byte order, and the first time your code talks to hardware or reads old data, little-endian assumptions leak all over the place. Ignoring portability buys you a pile of vendor-specific hacks later, because your team will meet those 'irrelevant' platforms in appliances, embedded boxes, or somebody else's DB import path long before a sales rep waves a support contract at you.

Re:Big-Endian Testing with QEMU by AKSF_Ackermann on Friday April 03, 2026 @12:34PM (#47628816)
Not sure why you consider that to be an issue, if you need to interact with a format that specifies values to be BE, just always byte-swap. And every appliance/embedded box i had to interact with ran either x86 or some flavour of 32-bit arm (in LE mode, of course).
Re:Big-Endian Testing with QEMU by 7jjjjjjj on Friday April 03, 2026 @01:02PM (#47629181)
Assuming an 8-bit byte used to be a "vendor specific hack." Assuming twos complement integers used to be a "vendor specific hack." When all the 36-bit machines died, and all the one's complement machines died, we got over it.

That's where big endian is now. All the BE architectures are dying or dead. No big endian system will ever be popular again. It's time for big endian to be consigned to the dustbin of history.

Re:Big-Endian Testing with QEMU by namibj on Friday April 03, 2026 @02:56PM (#47630608)
JS numbers behave much more like C's definition of signed overflow being UB as it's signed numbers are effectively like 51-ish bit with a SEPARATE sign bit and non-assiciative behavior when overflow happens.
Re:Big-Endian Testing with QEMU by zephen on Friday April 03, 2026 @02:30PM (#47630243)
> It's time for big endian to be consigned to the dustbin of history.

And, especially what most people call big-endian, which is a bastardized mixed-endian mess of most significant byte is zero, while least significant bit is likewise zero.

Re:Big-Endian Testing with QEMU by wpollock on Saturday April 04, 2026 @12:50AM (#47635878)
> And, especially what most people call big-endian, which is a bastardized mixed-endian mess of most significant byte is zero, while least significant bit is likewise zero.

In the 1980s at AT&T Bell Labs, I had to program 3B20 computers to process the phone network's data. 3B20s used the weird byte order 1324 (maybe it was 2413) and I had to tweak the network protocols to start packets with a BOM (byte order mark) (as the various switches that sent data didn't define endianess), then swap bytes accordingly.

Lesson learned was Never Ignore Endian issues.

Re:Big-Endian Testing with QEMU by jasomill on Saturday April 04, 2026 @02:04AM (#47636301)
While I have no personal experience with the 3B2 series, its documentation[1] clearly illustrates the GP's complaint: starting from the most significant binary digit, bit numbers decrease while byte addresses increase.

As for networking, Ethernet is particularly fun: least significant bit first, most significant byte first for multi-byte fields, with a 32-bit CRC calculated for a frame of length k by treating bit n of the frame as the coefficient of the (k - 1 - n)th order term of a (k - 1)th order polynomial, and sending the coefficients of the resulting 31st order polynomial highest-order coefficient first.

[1] https://vtda.org/docs/computing/AT&T/3B2/3b2_Assembly_Lang_P...

Re:Big-Endian Testing with QEMU by zephen on Saturday April 04, 2026 @05:04PM (#47643362)
I know this particular pain intimately.

I was in charge of the firmware for a modem. I had written the V.42 error correction, and we contracted out the addition of the MNP correction protocol. They used the same CRC.

The Indian (only important because of their cultural emphasis on book learning) subcontractor found my CRC function, decided it didn't quite look like the academic version they were expecting, and added code to swap it around and use it for MNP, thus making it wrong.

When I pointed out it was wrong, they claimed they had tested it. By having one of our modems talk to another one of our modems. Sheesh.

Re:Big-Endian Testing with QEMU by zephen on Saturday April 04, 2026 @04:57PM (#47643286)
> Lesson learned was Never Ignore Endian issues.

This is an excellent lesson for data transport protocols and file formats.

> I had to tweak the network protocols to start packets with a BOM (byte order mark) (as the various switches that sent data didn't define endianess), then swap bytes accordingly.

(A similar thing happened to me with the Python switch from 2 to 3. Strings all became unicode-encoded, and it's too difficult to add the b sigil in front of every string in a large codebase, so I simply ensured that at the very few places that data was transported to or from files, all the strings were properly converted to what the internal process expected.)

But, as many other commenters have rightly noted, big-endian CPUs are going the way of CPUs with 18 bit bytes that use ones-complement arithmetic, so unless you have a real need to run your program on a dinosaur, you can safely forget about CPU endianness issues.

Re:Big-Endian Testing with QEMU by jasomill on Saturday April 04, 2026 @01:13AM (#47636005)
While I have a strong personal preference for little endian, one thing I've always appreciated about IBM System/360 and its successors is that it at least has consistent notational conventions: most significant byte first, most significant bit zero[1][2].

[1] https://bitsavers.trailing-edge.com/pdf/ibm/360/princOps/A22...

[2] https://www.ibm.com/docs/en/SSQ2R2_15.0.0/com.ibm.tpf.toolki...

Re:Big-Endian Testing with QEMU by zephen on Saturday April 04, 2026 @04:52PM (#47643246)
> IBM System/360 and its successors ... at least has consistent notational conventions

Yes, if I hadn't known about that, I probably wouldn't have written "most."

> While I have a strong personal preference for little endian

Despite the porportedly even-handed treatment given in the seminal paper:

https://www.rfc-editor.org/ien/ien137.txt

That paper was obviously a product of motivated reasoning. And motivated reasoning in the hands of an intelligent and articulate person is always dangerous.

(Today, in the public sphere, we are seeing successful motivated reasoning by people who are much less intelligent and articulate, but that is a completely separate issue.)

The primary benefit (from observation of past arguments) that big-endian has is when you are dumping data and looking at a sequence of bytes, and don't want to mentally swap them around.

But that itself begs the question. If you are so keen on big-end first, then why does your dump start at the small end of memory?

Re:Big-Endian Testing with QEMU by imtringued on Saturday April 04, 2026 @08:25AM (#47638438)
Not just that. If you store a lower precision type e.g. 2 byte integer inside a large precision type e.g. 8 byte integer, you can read the 2 byte integer by just reading two bytes. Extending or shrinking data types leads to a very natural way of implementing arbitrary precision arithmetic. To get the same capability with big endian your pointer has to point at the end of the number. If you have byte arrays, like a string, you would have to swap the order in which you allocate data, starting from the end of the array and always decrement your index from the array pointer. This would then also apply this to struts. You point at the end of the struct and subtract the field offsets.

Overall this seems like a pretty weird choice on a planet where the vast majority of text is written from left to right and only numbers are written right to left. Especially since endianness only affects byte order but not bit order, as you said.

Re:Big-Endian Testing with QEMU by zephen on Saturday April 04, 2026 @04:58PM (#47643299)
The primary benefit touted for big-endian is "When I do a memory dump, the data looks right."

But if you really believe the left side is bigger, why do you put the smaller memory address on the left side of your dump?

Re:Big-Endian Testing with QEMU by cmrdporcupine on Friday April 03, 2026 @01:25PM (#47629464)
> No big endian system will ever be popular again

Cries in 68k nostalgia

Re:Big-Endian Testing with QEMU by adrian_b on Friday April 03, 2026 @02:20PM (#47630105)
Endianness problems should have been solved by compilers, not by programmers.

Most existing CPUs, have instructions to load and store memory data of various sizes into registers, while reversing the byte order.

So programs that work with big-endian data typically differ from those working with little-endian data just by replacing the load and store instructions.

Therefore you should have types like int16, int32, int64, int16_be, int32_be, int64_be, for little-endian integers and big-endian integers and the compiler should generate the appropriate code.

At least in the languages with user-defined data types and overloadable operators and functions, like C++, you can define these yourself, when the language does not provide them, instead of using ugly workarounds like htonl and the like, which can be very inefficient if the compiler is not clever enough to optimize them away.

Re:Big-Endian Testing with QEMU by wakawaka28 on Friday April 03, 2026 @09:47PM (#47634773)
If two machines have different endianness, then there is no optimal byte order for either one. Therefore, this problem can't be solved in a one-size-fits-all optimal solution. People have tried to make code generators to take some of the pain out of encoding/decoding but that isn't effortless either.
Re:Big-Endian Testing with QEMU by cbarrick on Saturday April 04, 2026 @11:47AM (#47640061)
Defining BE integer data types seems like a bad approach.

I wouldn't want to maintain those types. The maintainer would either have to implement all of the arithmetic operations or assume that your users would try to hack their way to arithmetic. But really, you shouldn't ever do arithmetic with non-native endianness anyway.

Instead, define all your interfaces to work with native endianness integers and just do byte swapping at the serialization boundaries.