omino code blog

We need code. Lots of code.

Four and Twenty Blackbirds

David Van Brink
// Sat 2007.10.27 13:04 // {numbers pointless}

The Endian is Nigh

Yes, yes, it’s a religious issue. And please to note that this post is filed under category “pointless”. I’m a little-endian, myself. If you’re reading this, you probably already know a little or too much about it… but the Wikipedia article is still a fun read.

Some things I like about little-endian ordering are:

  • For integers, bits are traditionally labeled 0 for the smallest-value bit, and each bit index n refers to the 2nth value position, it’s nice if byte-numbering, aka address, follows the same scheme. (The Wikipedia link above mentions that this bit-numbering is now nearly universal; that is to say, “bit zero” refers to the “ones” place.)
  • Similarly, the value of byte n of a multibyte integer is simply 256n.

Things that don’t matter are:

  • Basic arithmetic and comparisons are just as easy regardless of endianness. In all cases you need to know the size of the operands; counting upwards or downwards is of no consequence.

What I don’t like about little-endian ordering is:

  • In a hexdump, changing your word width causes the hexdump to “swizzle”. Anything other than byte mode shows the data in a ratcheted sequence.
    • In byte mode, your hexdump prints the numbers “backwards”

    Yup. Your standard little-endian hexdump of the number 0×12345678 is 78 56 34 12, and that’s no fun to read. Especially if you’re around big-endians to point out the folly.

    But here is a simple solution: Your hexdump should show ascii left-to-right, and hex right-to-left. Like so.

    Now we get all the advantages of consistency and readability at the same time! In fact, I’d recommend to implementors of memory-display UI’s to include a toggle for left-to-right or right-to-left hex. In the picture above, I’d want to click on the arrow.

    Historical Note

    “Well that’s nice, but showing bytes right-to-left is strange, and inconsistent,” the committed big-endian might reasonably remark. And they’d be correct. But we have only ourselves to blame, we the inheritors of the English language. English is written left-to-right, and in that sense our numbers are written big-endian: the most significant digits arrive first.

    Our numbers are Arabic, my friend. Arabic is written right-to-left. *

    English style:   We baked 24 blackbirds in a pie.
    Arabic style:    .eip a ni sdribkcalb 24 dekab eW
    

    It’s a compatibility nightmare.

    oh, i dont know. what do you think?


    mimeo wordpress theme by
    poly@omino.com
    +