5
$\begingroup$

The Portable Executable file format is the format that Windows EXE files use.

It is a binary format.

Numbers are in little endian form. Thus, the following hex represents the decimal number 256, not 1.

00 01

Some fields in the file format represent text strings. For example, the "Name" field contains a null-terminated string that has up to 8 characters. Here are the hex bytes for a name and in parentheses the corresponding string:

2E 64 61 74 61 00 00 00 (.data)

My question is this: The file's byte order is little endian and therefore the bytes in a number are interpreted from right-to-left. Why aren't the bytes in a string interpreted right-to-left? Why aren't the bytes for the above string this:

00 00 00 63 74 61 64 2E

Notice that I reversed the order of the bytes. That's not how it is in EXE files, but why not? Why does "little endian" apply only to numbers and not to text strings?

$\endgroup$
2
  • $\begingroup$ Little endian only makes sense for fixed width fields. $\endgroup$ Jan 21, 2019 at 15:56
  • $\begingroup$ Hi @Yuval Filmus. The Name field that I mentioned is a fixed-width field -- exactly 8 bytes. So, shouldn't little endian make sense for that field? $\endgroup$ Jan 21, 2019 at 16:55

2 Answers 2

6
$\begingroup$

The premise is wrong. Unicode encodings include UTF-16BE, UTF-16LE, UTF-32BE and UTF32-LE. Only UTF-8 has no Litte-Endian or Big-Endian variants.

Fundamentally, Endian-ness is about the byte order of multi-byte words, and you're thinking of text encodings which use a single byte per character (i.e. ASCII). There's no order to a single byte.

$\endgroup$
1
  • $\begingroup$ Ah! A truly keen insight! Thank you @MSalters! $\endgroup$ Jan 22, 2019 at 11:34
2
$\begingroup$

You certainly could do it that way. It's an arbitrary decision. You could store characters in ascending order, or in descending order.

$\endgroup$
3
  • $\begingroup$ Hi @D.W. Are you saying that there is no standard for representing the bytes of a text string in a binary file? Are you saying that the Portable Executable file format's approach of storing text bytes in left-to-right order (lower-to-higher memory addresses) is purely arbitrary? $\endgroup$ Jan 21, 2019 at 17:50
  • $\begingroup$ @RogerCostello, I didn't say there's no standard; I would assume there is a standard. I am saying it's arbitrary, and it would be possible to do the reverse. $\endgroup$
    – D.W.
    Jan 21, 2019 at 18:51
  • $\begingroup$ @RogerCostello If you write arabic, you most definitely do NOT store it in left-to-right order. That would be completely wrong. You also don't write it in left-to-right order. Mostly right to left, with some things left to right. For example "This shop is closed from 12:00 to 14:00" would become "14:00 ot 12:00 morf desolc si pohs sihT". $\endgroup$
    – gnasher729
    Mar 4 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.