A
A
avion2019-07-01 18:31:10
ASCII
avion, 2019-07-01 18:31:10

PC encodings?

Hello, how does the computer understand what encoding a certain file has? Where are the encoding tables stored? When keyboard input occurs, is it ASCII character input?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Moskus, 2019-07-01
@avion123678

Computers don't understand anything on their own, ever.
For some file types, the encoding is determined by their format, so programs that work with them always use the correct encoding.
For other file types, the encoding is specified in the header. For example, in HTML there is a tag for this. So programs read its contents and interpret the encoding correctly.
Encoding tables are not "hardwired" anywhere. They can be part of the operating system, they can be part of this or that software.
When keyboard input occurs, ASCII has nothing to do with it. The operating system receives the scan code of the key, and then generates a character in accordance with which keyboard layout is currently enabled. At the same time, what code of the same character it turns into also depends on the specific program. For example, if at this moment the command line is open, and the code page 866 is set in it, the Cyrillic character will turn into two bytes from the 866 character table. And if Word is open, it will turn into a Unicode character of more than two bytes.

S
SagePtr, 2019-07-01
@SagePtr

The computer - does not understand in any way, for him the file remains a sequence of zeros and ones.
Programs - depending on the file format, some formats allow you to specify the encoding in headers, meta-data or somewhere else, in some formats a certain encoding is clogged in the specification and you don't need to guess anything, some (for example, text editors) heuristically by a set of bytes try to guess, do not always do it correctly, and in the case of a single-byte encoding, rely on the current locale in the system. Encoding tables - hardwired into the programs themselves or into libraries used by programs for decoding (for example, iconv). Regarding the keyboard, the keyboard layout contains a table which key with which modifiers to which character to convert, ASCII is not used there (because ASCII allows you to use only a limited set of characters - numbers, basic Latin and basic punctuation)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question