Use Java to obtain the location code of Chinese Characters

Source: Internet
Author: User

Before sending code, go to the Section preparation

The prerequisite for a computer to process Chinese character information is to encode each Chinese character. These encodings are collectively referred to as Chinese character encoding. The process of transmitting Chinese character information in the system is the process of Chinese character encoding conversion.
Chinese Character Exchange Code: Unified encoding required for each Chinese character when information is transmitted between Chinese character information processing systems or between communication systems, china has designated the Chinese Character Exchange Code National Standard "the Chinese character encoding character set for information exchange-basic set", code: GB 2312-80, also known as the "National Standard Code ".
Chinese character code: All Chinese character codes should follow this standard. The Chinese Character machine internal code encoding, the Chinese character font design, the conversion of Chinese character input codes, and the Chinese character address code of the output device, based on this standard. GB 2312-80 is the country code. This Code specifies that a Chinese character is expressed in two bytes, each of which has only seven characters, similar to the ASCII code.
Location Code: A 94 × 94 square matrix composed of all the character sets of GB 2312-80, each row is called a "area" and numbered 0l ~ 94; each column is called a "bit" and numbered 0l ~ 94. In this way, the location map of GB 2312-80 is obtained. The Chinese character code expressed by the location map is called the location code.
Internal code: in order to avoid the problem of ambiguity when both ASCII code and National Code are used, most Chinese character systems use each byte height 1 as the internal code of Chinese characters. This not only solves the ambiguity between the Chinese character machine internal code and the Spanish character machine internal code, but also makes the Chinese character machine internal code and the national character code have a very simple ing relationship.
The relationship between the Chinese character machine internal code, the country code, and the location code is: the two bytes of the Location Code (decimal) are converted into hexadecimal notation and then added 20 h to obtain the corresponding country code; the inner code is the inner code obtained by adding 1 to the highest bits of the two Chinese Character Exchange codes (country code), that is, adding 80 h to the two bytes of the Chinese Character Exchange Code (country code). The location code (decimal) and then add a0h to obtain the corresponding internal code.

 

Public class wordcode {
Public static string bytes2hexstring (byte B ){
Return bytes2hexstring (New byte [] {B });
}

Public static string bytes2hexstring (byte [] B ){
String ret = "";
For (INT I = 0; I <B. length; I ++ ){
String hex = integer. tohexstring (B [I] & 0xff );
If (Hex. Length () = 1 ){
Hex = '0' + hex;
}
RET + = Hex. touppercase ();
}
Return ret;
}

Public static void main (string [] ARGs) throws exception {
String STR = "sun ";
Byte [] BS = Str. getbytes ("gb2312 ");
String S = "";
For (INT I = 0; I <BS. length; I ++ ){
Int A = integer. parseint (bytes2hexstring (BS [I]), 16 );
S + = (a-0x80-0x20) + "";
}
System. Out. println (s );
}

}

 

The last website to be queried

Http://www.jscj.com/index/gb2312.php

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.