我自己写了一个函数,给你吧: {********************************************************} { Written By BlazingFire 2002.10 } { This function can transfer a binary string } { to a hex string. } {********************************************************}function BinToHexEx(BinS:String):String; const HexArray:Array[0..15] of Char =('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); var Value:Integer; TmpStr:String; begin BinS:=Trim(BinS); for Value:=1 to Length(BinS) do begin if Not(BinS[Value] in ['0','1']) then begin Result:='Wrong binray string!'; Exit; end; end; Result:=''; while Length(BinS)>0 do begin Value:=0; if Length(BinS)<=4 then begin TmpStr:=BinS; BinS:=''; while Length(TmpStr)<4 do TmpStr:='0'+TmpStr; end else begin TmpStr:=Copy(BinS,Length(BinS)-3,4); BinS:=Copy(BinS,1,Length(BinS)-4); end; if TmpStr[1]='1' then Inc(Value,8); if TmpStr[2]='1' then Inc(Value,4); if TmpStr[3]='1' then Inc(Value,2); if TmpStr[4]='1' then Inc(Value); Result:=HexArray[Value]+Result; end; end;//好象Delphi自己的函数用起来很不爽
{********************************************************}
{ Written By BlazingFire 2002.10 }
{ This function can transfer a binary string }
{ to a hex string. }
{********************************************************}function BinToHexEx(BinS:String):String;
const
HexArray:Array[0..15] of Char
=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
var
Value:Integer;
TmpStr:String;
begin
BinS:=Trim(BinS);
for Value:=1 to Length(BinS) do
begin
if Not(BinS[Value] in ['0','1']) then
begin
Result:='Wrong binray string!';
Exit;
end;
end;
Result:='';
while Length(BinS)>0 do
begin
Value:=0;
if Length(BinS)<=4 then
begin
TmpStr:=BinS;
BinS:='';
while Length(TmpStr)<4 do TmpStr:='0'+TmpStr;
end
else
begin
TmpStr:=Copy(BinS,Length(BinS)-3,4);
BinS:=Copy(BinS,1,Length(BinS)-4);
end;
if TmpStr[1]='1' then Inc(Value,8);
if TmpStr[2]='1' then Inc(Value,4);
if TmpStr[3]='1' then Inc(Value,2);
if TmpStr[4]='1' then Inc(Value);
Result:=HexArray[Value]+Result;
end;
end;//好象Delphi自己的函数用起来很不爽