[ELI5] Why does Notepad display a wall of garbled text when opening a non-.txt file?

533 views

Every so often, if I open a non-text based document in either Microsoft Word or Notepad, it will open a massive file with an endless wall of completely garbled, gibberish text, most of the characters being either rectangle boxes or characters that can’t normally be typed. What does each of these characters represent? What happens if I insert or delete these characters?

Usually files would refuse to open with an incompatible format. How do these text-processing softwares somehow manage to run virtually any file?

In: 15

13 Answers

Anonymous 0 Comments

Files are in a certain format and the application opening them checks if the format is valid (as expected).
Random files will not be valid and the application refuses to open them.
Ex: Most image file are expected to have a special area defining the with/heigth, number of colors, etc..

A text editor, such as notepad, is not expecting a certain file format and can open any file.(some constraints about size, etc… but that is irrelevant.
The garbled text you see is because of the way Notepad tries to interpret the file as text.

All characters are encoded as a string of bits.
Memory was precious and a long time ago, characters where encoded using 7 bits (Not even a full byte to save a single bit per character.) (Standard ASCII character set)
Later 8 bits per character were used. (Extended ASCII character set)
Today multiples of 8-bits (even up ti 4 bytes) can be used per character to display all the special ones, such as Chinese, Japanese characters.

For files that are not text, other encodings can be used.
The same string of bits might have a completely different meaning. (For a compiled application it might be an instruction for the CPU.)

As notepad is a very simple editor and doesn’t know about all this, it just displays each byte of a file as an individual character from the ASCII character set, resulting in what you see.

You can see the (extended) ASCII character set here: https://www.asciitable.com/

You are viewing 1 out of 13 answers, click here to view all answers.