Comment

Comment by kentonv

Big-endian vs. little-endian is an ancient flamewar that isn't going to go away any time soon, but sure, let's argue.

Once you've spent as much time twiddling bits as I have (as the author of proto2 and Cap'n Proto), you start to realize that little endian is much easier to work with than big-endian.

For example:

- To reinterpret a 64-bit number as 32-bit in BE, you have to add 4 bytes to your pointer. In LE, the pointer doesn't change.

- Just about any arithmetic operation on integers (e.g. adding) starts from the least-significant bits and moves up. It's nice if that can mean iterating forward from the start instead of backwards from the end, e.g. when implementing a "bignum" library.

- Which of the following is simpler?

    // Extract nth bit from byte array, assuming LE order.
    (bytes[n/8] >> (n%8)) & 1

    // Extract nth bit from byte array, assuming BE order.
    (bytes[n/8] >> (7 - n%8)) & 1
There's really no good argument for big-endian encoding except that it's the ordering that we humans use in writing.

I think the correct answer won here.

parent kentonv 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton