HTML and JavaScript encoding problems frequently encountered page 1/2

Source: Internet
Author: User

Here I will briefly discuss the coding problems that often occur in the daily work of front-end HTML and JavaScript.
In the computer, the information we store is represented by binary code. What we know, the English and Chinese characters displayed on the screen, and the binary used for storage Code Is the encoding.

There are two basic concepts to describe: charset and character encoding:

Charset, character set, is a table of the ing between a symbol and a number, that is, it determines that 107 is the 'a' of koubei, and 21475 is the "Port" of reputation ", different tables have different ing relationships, such as ASCII, gb2312, and Unicode. through this ing table of numbers and characters, we can convert a binary number into a certain character.
Chracter encoding: encoding method. For example, do we use \ u5k3e3 or % E5 % 8f % A3 to represent the 21475 value of the Response port? This is determined by character encoding.

For 'kubei. com 'is a common character set of Americans. They developed an ASCII character set, which is short for American Standard Code of information interchange, use the 128 numbers 0-128 (the power of 2, 0 × 00-0 × 7f) to represent the commonly used characters such as 123abc. A total of 7 bits, plus the first is the symbol bit, to use the complement code to represent a negative number or something, a total of 8 bits constitute a byte. The Americans were just a little stingy. If we designed a byte as 16 bits and 32 bits from the very beginning, there would be fewer problems in the world, but at that time, they thought 8 bits would be enough, it can represent 128 different characters!

This computer is made up by Americans, so they save time and code all their household symbols. But when the computer started internationalization, the problem came out. Let's take China as an example. There are tens of thousands of Chinese characters. What should I do?

The existing 8 bits one-byte system is the foundation and cannot be damaged. It cannot be changed to 16 bits or the like. Otherwise, the change is too large and you can only take another path: multiple ASCII characters are used to represent one other character, that is, MBCS (Multi-byte character system, multi-Byte Character System ).
With the concept of MBCS, we can represent more characters. For example, if we use 2 ASCII characters, we can use 16 bits. Theoretically, we can use 2 to the power of 16 to 65536 characters. But how can these encodings be assigned to characters? For example, the Unicode code of koubei's "Port" is 21475. who decides? Character Set, that is, the charset just introduced. ASCII is the most basic character set, on which we have MBCS character sets similar to gb2312 and big5 for simplified Chinese and Traditional Chinese. Finally, a mechanism called UNICODE consortium decided to create a character set including all characters (UCS, Universal Character Set) and the corresponding encoding standard, that is, Unicode. Since 1991, it has released the first International Unicode standard, ISBN 0-321-18578-1, and ISO has also participated in this customization. ISO/IEC 10646: the universal character set. In short, Unicode is a character standard that basically covers all existing symbols on the earth, and is now widely used. The ECMA standard also stipulates that, the internal characters in the Javascript language use the Unicode Standard (this means that the Javascript variable name and function name are allowed in Chinese !).

Developers in China may encounter many problems, such as conversion between GBK, gb2312, and UTF-8. Strictly speaking, this statement is not very accurate. GBK and gb2312 are character sets, while UTF-8 is a encoding method (character encoding ), is a Unicode Standard in the UCS character set encoding method, because the use of Unicode character sets of web pages mainly using UTF-8 encoding, so they are often tied, in fact, is not accurate.

With Unicode, at least before human civilization encounters aliens, This Is A omnipotent key. Use it. And now the most widely used unicode encoding method is the UTF-8 (8-bit UCS/Unicode Transformation Format), it has a few particularly good places:

It is a world-class, world-class
Is a variable-length encoding method (variable-length character encoding), compatible with ASCII
The second advantage is that it makes the previous pure ASCII encoding system compatible and does not increase the additional storage (false setting of long encoding mode, it is specified that each character is composed of two bytes, so the storage space occupied by ASCII characters will increase by a factor ).

Related Article

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.