求助:(急) ( 积分: 100 )

  • 主题发起人 big-small
  • 开始时间
B

big-small

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手:
我想把一个word型16位二进制转换为汉字;怎么办?byte型8位二进制转化为字母
有没有函数可以用
 
各位高手:
我想把一个word型16位二进制转换为汉字;怎么办?byte型8位二进制转化为字母
有没有函数可以用
 
BinToHex -> 高8位、第8位
 
var
A: WideChar;
B: Char;
C: Byte;
D: Word;
E: String;
begin
A := WideChar(D);

E := String(A);
B := Char(C);
end;
 
i : Integer;
ch, cl : Integer;
i := 53947;
//'一'
ch := i Div 256;
cl := i Mod 256;
Edit1.Text := Chr(ch) + Chr(cl);
 
//机内码 -> 汉字
Function MacCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : Integer;
begin
ch := AiUniCode Div 256;
cl := AiUniCode Mod 256;
Result := Chr(ch) + Chr(cl);
end;

//汉字 -> 机内码
Function Chinese2MacCode(AiChinese : String) : Integer;
Var
ch, cl : Integer;
begin
ch := Ord(AiChinese[1]);
cl := Ord(AiChinese[2]);
Result := (ch shl 8) + cl;
end;

//UniCode -> 汉字
Function UniCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : String[3];
s : String;
begin
s := IntToHex(AiUniCode, 2);
cl := '$' + Copy(s, 1, 2);
ch := '$' + Copy(s, 3, 2);
s := Chr(StrToInt(ch)) + Chr(StrToInt(cl)) + #0;
Result := WideCharToString(pWideChar(s));
end;

//汉字 -> UniCode
Function Chinese2UniCode(AiChinese : String) : Integer;
Var
ch, cl : String[2];
a : array [1..2] of char;
begin
StringToWideChar(Copy(AiChinese, 1, 2), @(a[1]), 2);
ch := IntToHex(Integer(a[2]), 2);
cl := IntToHex(Integer(a[1]), 2);
Result := StrToInt('$' + ch + cl);
end;
 
我也认为如此:
//机内码 -> 汉字
Function MacCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : Integer;
begin
ch := AiUniCode Div 256;
cl := AiUniCode Mod 256;
Result := Chr(ch) + Chr(cl);
end;

//汉字 -> 机内码
Function Chinese2MacCode(AiChinese : String) : Integer;
Var
ch, cl : Integer;
begin
ch := Ord(AiChinese[1]);
cl := Ord(AiChinese[2]);
Result := (ch shl 8) + cl;
end;

//UniCode -> 汉字
Function UniCode2Chinese(AiUniCode : Integer) : String;
Var
ch, cl : String[3];
s : String;
begin
s := IntToHex(AiUniCode, 2);
cl := '$' + Copy(s, 1, 2);
ch := '$' + Copy(s, 3, 2);
s := Chr(StrToInt(ch)) + Chr(StrToInt(cl)) + #0;
Result := WideCharToString(pWideChar(s));
end;

//汉字 -> UniCode
Function Chinese2UniCode(AiChinese : String) : Integer;
Var
ch, cl : String[2];
a : array [1..2] of char;
begin
StringToWideChar(Copy(AiChinese, 1, 2), @(a[1]), 2);
ch := IntToHex(Integer(a[2]), 2);
cl := IntToHex(Integer(a[1]), 2);
Result := StrToInt('$' + ch + cl);
end;
 

Similar threads

S
回复
0
查看
956
SUNSTONE的Delphi笔记
S
S
回复
0
查看
778
SUNSTONE的Delphi笔记
S
D
回复
0
查看
828
DelphiTeacher的专栏
D
D
回复
0
查看
630
DelphiTeacher的专栏
D
D
回复
0
查看
605
DelphiTeacher的专栏
D
顶部