Reason for introducing encoding: The computer can only store binary numbers. Therefore, in order to store characters, it is necessary to store the binary number of the corresponding code table number.
Does not directly deposit the corresponding character outline. When displayed, the binary number is converted to a decimal number to find the corresponding code table.
to decode.
ASCII: First code table, only for Latin characters and common symbols
a--97 z--122 a--65 z--90
0--48 1--49 9--57
The Code table has a total of 128 pairs, 0-127 of the number, each number represents a character. A character represents a byte.
The Code table corresponds to a 7-bit binary number, but the basic unit of computer processing is a byte, that is, 8 bits, so the highest bit is replaced with a.
Later, the character is not enough to expand it by 128 characters, which is 256 characters. The highest bits are 1. It is called extended ASCII code.
GB2312: China's own code table, 0-127 numbers are ASCII encoding, followed by some Chinese characters, which also contains some ASCII code some symbols, but these symbols are occupied two bytes,
is often said "full-width" symbol, ASCII code is called "Half-width" character. This Code table contains simplified Chinese.
GBK: It is also China's Code table, on the basis of gb2312. Contains traditional characters.
GB18030: On the basis of GBK, the majority of minority characters commonly used are included.
In the above Chinese code table, the alphanumeric characters are 1 bytes and the kanji is two bytes.
Unicode: Also known as the Universal Code. Contains most of the text in the world. The default code table for Java, which is a 16-bit code table. In Java, two bytes are used to represent one character.
For those "half-width" characters in ASCII, Unicode retains its original encoding, only extending its length from 8 bits to 16 bits, while the characters in other cultures and languages are all re-encoded.
Because Unicode stipulates that all characters account for two bytes, the original English characters in the ASCII code only need one byte to be able to store, it is necessary to waste half of the space to store, is a great waste of resources.
Utf-8: is one of the most widely used Unicode implementations on the Internet, which is encoded for transmission, and makes coding borderless, and UTF-8 is a variable encoding method.
It can use 1~4 bytes to represent a symbol, varying the length of a byte depending on the symbol, and when the character is in the ASCII range, it is represented by a byte,
The ASCII character is preserved as a byte of encoding as part of it, UTF-8 a Chinese character for 3 bytes. From Unicode to uft-8 is not a direct correspondence, but a number of algorithms and rules to convert.
In the above code table, the corresponding binary number is not the same, so we can get the root cause of the Chinese garbled is the coding and decoding with a different code table.
Byte is byte, bit is bit,1 byte = 8 bit, that is, one byte has 8 bits.
"Byte" is a 8-bit physical storage unit, while "character" is a culture-related symbol.
Java...... About encoding