When I open a binary file in vim, I see the mnemonics instead of the 0s
and 1s
. I believe this is due to the fact that vim by default opens the file in ASCII mode. Is my understanding right? What is the encoding format of a binary file? Is it UTF-8? I know xxd
will hex-dump the binary file in Vim
. However I would like to know why vim or any text editor doesn't show the binary file as 0s
and 1s
.

- 333,661

- 289
1 Answers
On all modern operating systems, any binary file is going to be stored and handled as a series of bytes (that is, 8-bit groups). In fact, any text file will also be stored this way.
In most cases, text editors (or binary file editors) are designed to show bytes because they are the unit of storage. If I want to edit a binary file to contain a different value, it is more useful to me to edit one byte at a time rather than to edit multiple bits at a time. For example, if I'm editing a data file to change a value from 1234 to 5678, it's much easier to search for the bytes 04 d2
or d2 04
and then swap them to 16 2e
or 2e 16
than it is to find some series of bits in a stream which isn't byte aligned.
Vim, as well as many other text editors, will open binary files in a mode that uses a single-byte encoding (in Vim, usually latin1
). What encoding it uses is not really interesting, because character encodings are used for text data—that is, data that represents something intelligible to a human—and not binary data. The purpose of using a single-byte encoding is that any byte sequence is valid and that no modification occurs when loading or saving.
Finally, be aware that even binary files usually have some sort of structure, even if it isn't as apparent as for text files. For example, an ELF file will start with the byte 0x7f and then the characters ELF
. It will then contain bytes for the class (32-bit or 64-bit), endianness, version, and ABI. These just aren't in forms that are readily readable unless you're familiar with the format, unlike text files.

- 4,099
- 7
- 9
TL;DR
in binary (small-endian) -- did you spot that? – Paul_Pedant Jun 27 '20 at 09:56