Result:='0'+Result;
end;
//将一个十六进制字符串转换成十进制数值
Function HexToInt(Hex: string): Int64;
Begin
Result:=strtoint64('$'+Hex);
End;
//将一个十六进制字符串转换成二进制数值
Function HexToBin(Hex: string): string;
var
icnt:integer;
sRes:string;
sHexOne:string;
begin
sRes:='';
for icnt:=length(Hex) downto 1 do
begin
sHexOne:=copy(Hex,icnt,1);
if sHexOne ='0' then sRes:='0000'+sRes
else if sHexOne ='1' then sRes:='0001'+sRes
else if sHexOne ='2' then sRes:='0010'+sRes
else if sHexOne ='3' then sRes:='0011'+sRes
else if sHexOne ='4' then sRes:='0100'+sRes
else if sHexOne ='5' then sRes:='0101'+sRes
else if sHexOne ='6' then sRes:='0110'+sRes
else if sHexOne ='7' then sRes:='0111'+sRes
else if sHexOne ='8' then sRes:='1000'+sRes
else if sHexOne ='9' then sRes:='1001'+sRes
else if sHexOne ='A' then sRes:='1010'+sRes
else if sHexOne ='B' then sRes:='1011'+sRes
else if sHexOne ='C' then sRes:='1100'+sRes
else if sHexOne ='D' then sRes:='1101'+sRes
else if sHexOne ='E' then sRes:='1110'+sRes
else if sHexOne ='F' then sRes:='1111'+sRes;
end;
while copy(sRes,1,1)='0' do
sRes:=copy(sRes,2,length(sRes));
if sRes='' then
sRes:='0';
Result:=sRes;
End;
//二进制转十六进制
Function BinToHex(Bin:string):string;
var
iLen:integer;
sBinAll:string;
sBinOne:string;
sRes:string;
begin
if 4-(length(Bin) Mod 4)>0 then
sBinAll:=copy('0000',1,4-(length(Bin) Mod 4))+Bin
else
sBinAll:=Bin;
iLen:=trunc(length(sBinAll)/4);
sRes:='';
while iLen>0 do
begin
sBinOne:=copy(sBinAll,length(sBinAll)-3,4);
if sBinOne ='0000' then sRes:='0'+sRes
else if sBinOne ='0001' then sRes:='1'+sRes
else if sBinOne ='0010' then sRes:='2'+sRes
else if sBinOne ='0011' then sRes:='3'+sRes
else if sBinOne ='0100' then sRes:='4'+sRes
else if sBinOne ='0101' then sRes:='5'+sRes
else if sBinOne ='0110' then sRes:='6'+sRes
else if sBinOne ='0111' then sRes:='7'+sRes
else if sBinOne ='1000' then sRes:='8'+sRes
else if sBinOne ='1001' then sRes:='9'+sRes
else if sBinOne ='1010' then sRes:='A'+sRes
else if sBinOne ='1011' then sRes:='B'+sRes
else if sBinOne ='1100' then sRes:='C'+sRes
else if sBinOne ='1101' then sRes:='D'+sRes
else if sBinOne ='1110' then sRes:='E'+sRes
else if sBinOne ='1111' then sRes:='F'+sRes;
sBinAll:=copy(sBinAll,1,length(sBinAll)-4);
iLen:=length(sBinAll);
end;
if sRes='' then
sRes:='0';
Result:=sRes;
end;
//将一个二进制字符串转换成十进制数值
Function BinToInt(Bin: string): Int64;
Begin
Result:=HexToInt(BinToHex(Bin));
End;
//将一个十进制整型转换成二进制值
//参数说明:
//Int:被转换的整型值
//Size:转换后的宽度:4位 8位 或更大 设为0则由系统自动判断
Function IntToBin(Int: Int64;Size: Integer=0): String;
Begin
Result:=HexToBin(System.SysUtils.IntToHex(int,0));
if Size>0 then
while length(Result)
Result:='0'+Result;
End;