Uncode and UTF-8 of encoding: Bloody details

Source: Internet
Author: User
Uncode and UTF-8 of encoding: Bloody details of the Uncode and UTF-8: Bloody details and encountered the problem of encoding, describe it with this sentence in the "no-nonsense XML" of the two tigers.
The only way to solve the problem is to clarify the concept.
Encoding is a ing table between integers and characters.
Unicode encoding uses 16 bits to store this integer.
UTF8 can contain up to 6 bytes. UT8 is another encoding, But it indirectly uses a unicode encoding table to map characters. It is converted to produce unicode values directly.
1. UTF8 0 ~ 128 and ASCII code 0 ~ 128 is consistent, except that UT8 uses two bytes, and acⅱ uses one byte.

2. All non-ACSII characters are represented by more than one byte. Each byte is expressed as a negative integer (the highest bit is 1), so no byte contains 0 ~ 128
The first byte is always between 0xC0 and 0xFD. It indicates that this character uses several bytes. There are several bytes starting with 1,
For example, if the first byte is 110 xxxxx, it indicates that there are two bytes. The first byte is 1110 xxxx, indicating that there are three bytes. 0XFD = 11111101, so in theory, UTF8 can contain up to 6 bytes.
The value of each byte (including the first byte) on the right of the first zero is the bit used. The first byte always appears with n 1 plus one 0 plus m digits left in place, other bytes are always in the form of 10 + 6 remaining bits (that is, they are always between 0x80 and 0xBF .)
The values of all the remaining bits are the values of this character in the Unicode encoding table.
For example:
Unicode Character U + 2260 = 0010 0010 0110 0000
UTF8: 1110 (0010) 10 (001001) 10 (100000) = 0xE2 0x89 0xA0
The extracted values in the brackets are combined to form the unicode value.

3. UTF8 does not use 0xFE to 0xFF values

 

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.