BIG5 code to BG code conversion technology

Source: Internet
Author: User
Tags fread range

Because the quantity is too many, it is different from the English one byte in ASCII code, it uses two byte to express. By calculating these two bytes, we can get the position of the Chinese characters in the Chinese font. Reads a number of bytes from that location to obtain the bitmap information that represents the Chinese character. With this information, you can display the kanji separately in DOS or Windows. In fact, the text file is saved in the corresponding two bytes per Chinese character encoding, and the display problem is automatically resolved by the Chinese operating system.

Encoding is not uniform, we use GB code, and Taiwan is using BIG5 code. BIG5 code file to save the corresponding BIG5 encoding of Chinese characters, GB code files are stored in the corresponding GB code (this is the "garbled phenomenon" of origin). So the key to the conversion work is to have a file that records each BIG5 encoding corresponding to the GB encoded Code table.

The first step is to make the Code table file

BIG5 code Coding rules are: Each Chinese character is composed of two bytes, the first byte range from 0x81-0xfe, a total of 126 kinds. The second byte range is 0x40-0x7e,0xa1-0xfe, a total of 157 species. In other words, the two bytes can be used to define a total of 126 * 157=19782 characters. These characters are part of our commonly used, such as, ding, these words we call common characters, its BIG5 code range of 0xa440-0xc671, a total of 5,401. Less commonly used words, such as abuse, modulation, we call the second word, the range of 0XC940-0XF9FE, a total of 7,652, the rest is some special characters.

The principle of making a Code table file is this: first of all the BIG5 encoding to write a file, and then, with BIG5 code to the GB code conversion function software, such as the global Village, the Orient Express, four-way, the file converted to GB code files, that is, to get the Code table files.

The following source program writes all possible BIG5 encodings (0xa100-0xfeff) to the file "Table.TXT".

//TURBO C++ 3.0
#include <Stdio.h>
#include <stdlib.h>
void main(){
FILE * codefile;
int I,j,k;
codefile=fopen("table.txt","w+b");
for (i=0xa1;i<=0xfe;I++){
for(j=0x00;j<=0xff;j++){
fwrite(& I,1,1,codefile);
fwrite(& j,1,1,codefile);}
}
fclose(codefile);
return;
}

Run the global village, Orient Express or four-lane, the "Table.txt" from the BIG5 code to GB code, that is, to obtain Code table files.

Second Step conversion

The following source program converts the BIG5 code file to a GB code file.

//turbo c++3.0
#include <stdio.h>
#include <stdlib.h>
Void Main () {
int que, Wei;
FILE * sourcefile;
FILE * tabfile;
FILE * destfile;
SourceFile = fopen ("Big.txt", "r+b");
//big5 code file
Tabfile = fopen ("Table.txt", ' r+b ');
Code Table file
DestFile = fopen ("Gb.txt", "w+b");
Transforms the generated GB code file
while (!feof (sourcefile)) {
Fread (& que,1,1,sourcefile);
if (feof (sourcefile)) {
break;}
if (que> =0xa1 && que <=0xfe)
//Renegade whether kanji (BIG5 code)
{fread (& wei,1,1,sourcefile);
if (wei<0xa1) Wei = wei-0x40;
if (wei>=0xa1) Wei = wei-0xa1 + 0x7e-0x40 + 1;
Fseek (Tabfile, 2 * (QUE-0XA1) * (0XFE-0XA1 + 1 + 0x7e-0x40 + 1) + Wei), seek_set);
Fread (& Que,1,1,tabfile);
Fread (& Wei,1,1,tabfile);
Fwrite (& Que,1,1,destfile);
Fwrite (& Wei,1,1,destfile);
}
Else
fwrite (& Que,1,1,destfile);//Processing English
}
fclose (sourcefile);
Fclose (Tabfile);
Fclose (destfile);
return;
}

The above procedure is passed in win95/97,tc3.0. Slightly modified, can also be used in CB, VC or VB program. In the same way, we can also convert GB code to BIG5 code.

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.