標籤:ar sp for on bs amp as tt nbsp
/****************************16進位轉漢字***********************************/
AnsiString TForm1::Hex_To_Chinese(AnsiString Hex)
{
//中英文數字參雜在一起也可以轉換
AnsiString ret;
for(int i=1; i<Hex.Length()+1; i += 2)
{
AnsiString TempStr = "0x" + Hex.SubString(i,2);
ret += AnsiString((char)(TempStr.ToInt()));
}
return ret;
}
/****************************16進位轉漢字***********************************/
/****************************漢字轉16進位***********************************/
AnsiString TForm1::Chinese_To_Hex(char* P_BCD, int iLen)
{
//中英文數字參雜在一起也可以轉換
AnsiString ret = "";
char hChar, lChar, Temp;
for (int i=0; i<iLen; i++)
{
Temp = *P_BCD++;
hChar = (Temp&0xF0)>>4;
lChar = (Temp&0x0F);
if ((hChar >= 0x00)&&(hChar <= 0x09))
hChar += 0x30;
if ((hChar >= 0x0A)&&(hChar <= 0x0F))
hChar += 0x37;
if ((lChar >= 0x00)&&(lChar <= 0x09))
lChar += 0x30;
if ((lChar >= 0x0A)&&(lChar <= 0x0F))
lChar += 0x37;
ret += AnsiString(hChar);
ret += AnsiString(lChar);
}
return ret;
}
/****************************漢字轉16進位***********************************/
void __fastcall TForm1::Button4Click(TObject *Sender)
{
String strChinese = "中國共滻黨萬歲";
//D6D0B9FAB9B29BBAB5B3CDF2CBEA 此段為漢字的機內碼
String strTemp = Chinese_To_Hex(strChinese.c_str(), strChinese.Length());
//Chinese_To_Hex()此函數轉的是機內碼 不是GB碼
ShowMessage(strTemp);
strTemp = Hex_To_Chinese(strTemp);
ShowMessage(strTemp);
};
16進位和漢字之間的互轉!《轉》