At the earliest, only 127 letters were encoded into the computer, that is, letters, numbers, and symbols in uppercase and lowercase, and this coded table is called ASCII coding.
is to deal with Chinese obviously a byte is not enough, need at least two bytes, and can not conflict with ASCII encoding, so, China has developed a GB2312 code to put Chinese into.
Unicode unifies all languages into a set of encodings, so there is no more garbled problem.
ASCII encoding is 1 bytes, while Unicode encoding is usually 2 bytes.
If ASCII encoding is A encoded in Unicode, you only need to make 0 in front.
In the spirit of saving, there has been the conversion of Unicode encoding to "Variable length encoding" UTF-8 encoding. The UTF-8 encoding encodes a Unicode character into 1-6 bytes according to a different number size, the commonly used English letter is encoded in 1 bytes, the kanji is usually 3 bytes, and only the very uncommon characters are encoded into 4-6 bytes. If the text you want to transfer contains a large number of English characters, you can save space by coding with UTF-8
Character |
Ascii |
Unicode |
UTF-8 |
A |
01000001 |
0000000001000001 |
01000001 |
In |
X |
01001110 00101101 |
11100100 10111000 10101101 |
In computer memory, Unicode encoding is used uniformly, and is converted to UTF-8 encoding when it needs to be saved to the hard disk or when it needs to be transferred.
When editing with Notepad, the UTF-8 characters read from the file are converted to Unicode characters into memory, and when the edits are complete, the conversion of Unicode to UTF-8 is saved to the file.
When you browse the Web, the server converts dynamically generated Unicode content to UTF-8 and then to the browser: