0
$\begingroup$

I have stumbled about the way a text file is saved by the OS. I have typed:

printf "ab" | hexdump

and the output was:

6261

which are the letters in reversed order. My first intent was endianess, but this cannot be true, since at this level, such abstractions must be transparent to the programmer and user. Also endian would be:

$$ab \mapsto 6162 \mapsto 2616$$

So I wondered, why would someone save a file like that?

Greetings, Niclas

$\endgroup$
0
$\begingroup$

I'm not sure this is the right place for this question. Anyway, hexdump is interpreting your input as a 16-bit little-endian number, therefore the bytes 0x61 and 0x62 (which leave the pipe in the "correct" order) appear reversed. Try printf "ab" | hexdump -C .

00000000  61 62                                             |ab|
00000002
| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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