DBCS and UCS Encoding

Source: Internet
Author: User

ASCII, gb2312, and GBK to gb18030 are both backward compatible. Among them, gb2312 and GBK to gb18030 both belong to the dual-byte character set (DBCS character set)
Unicode is ANSI compatible. For example, the Unicode encoding of the Chinese character is 6c49, And the GB encoding is Baba.
The Unicode name is "Universal multiple-octet coded chasracter set", for short
UCOS only specifies how to encode and does not specify how to transmit and save the encoding. For example, the "Han" character's UCS code is 6c49,
I can use four ASCII numbers to transmit and save this encoding. I can also use UTF-8 encoding: three consecutive bytes E6 B1 89 to represent it.
The key lies in the approval of both parties. UTF-8, UTF-7, UTF-16 are widely accepted solutions.

The UTF-8 is coded in 8 bits. The encoding from UCS-2 to UTF-8 is as follows:
UCS-2 encoding (hexadecimal) UTF-8 byte stream (Binary) 0000-007f 0 xxxxxxx 0080-07ff 110 XXXXX 10 xxxxxx 0800-FFFF 1110 XXXX 10 xxxxxx 10 xxxxxx
For example, the Unicode code of the Chinese character is 6c49. 6c49 is between 0800-ffff, so it must use a 3-byte template: 1110 XXXX 10 xxxxxx 10 xxxxxx. Write 6c49 as a binary: 0110 110001 001001,
Use this bitstream to replace X in the template in sequence. The result is 11100110 10110001 10001001, that is, E6 B1 89.
 
 
The UTF-8 is encoded in bytes and there is no issue of bytecode. The UTF-16 uses two bytes as the encoding unit. before interpreting a UTF-16 text, you must first understand the byte order of each encoding unit. For example, the Unicode encoding of "Kui" is 594e and that of "B" is 4e59. If we receive the UTF-16 byte stream "594e", is this "Kui" or "B "?
The recommended method for marking byte order in Unicode specifications is Bom. Bom is not a "bill of material" Bom, but a byte order mark. Bom is a bit clever:
There is a character named "Zero Width no-break space" in the UCS encoding, and its encoding is feff. Fffe does not exist in the UCs, so it should not appear in actual transmission. We recommend that you transmit the character "Zero Width no-break space" before transmitting the byte stream in the UCS specification ".
In this way, if the receiver receives feff, it indicates that the byte stream is big-Endian; if it receives fffe, it indicates that the byte stream is little-Endian. Therefore, the character "Zero Width no-break space" is also called Bom.
The UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code for the character "Zero Width no-break space" is ef bb bf (the reader can verify it with the encoding method we described earlier ). So if the receiver receives a byte stream starting with ef bb bf, it will know that this is UTF-8 encoding.
Windows uses BOM to mark the encoding of text files.

Therefore, GBK, utf8, UTF16 (small-end), UTF16 (large-end), and binary

Ba, ef bb bf E6 B1 89, FF Fe 49 6c, Fe FF 6C 49

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.