您好,登录后才能下订单哦!
//-----------------------------------------------
//16进制字符转整数,16进制字符与字符串转换中间函数
//-----------------------------------------------
function HexToInt2(hex: AnsiString): integer;
var
i: integer;
function Ncf(num, f: integer): integer;
var
i: integer;
begin
Result := 1;
if f = 0 then exit;
for i := 1 to f do
result := result * num;
end;
function HexCharToInt(HexToken: Ansichar): integer;
begin
if Ord(HexToken) > 97 then
HexToken := Ansichar(Chr(Ord(HexToken) - 32));
Result := 0;
if (Ord(HexToken) > 47) and (Ord(HexToken) < 58) then { chars 0....9 }
Result := Ord(HexToken) - 48
else if (Ord(HexToken) > 64) and (Ord(HexToken) < 71) then { chars A....F }
Result := Ord(HexToken) - 55;
end;
var
a16int:Integer;
ancf:integer;
begin
result := 0;
hex := ansiuppercase(trim(hex));
if hex = '' then
exit;
for i := 1 to length(hex) do
// result := result + HexCharToInt(hex[i]) * ncf(16, length(hex) - i);
begin
a16int := HexCharToInt(hex[i]);
ancf := ncf(16, length(hex) - i);
result := result + a16int * ancf;
end;
end;
//-----------------------------------------------
//16进制字符转字符串
//-----------------------------------------------
function hextostring(str: AnsiString): AnsiString;
var
s:AnsiString;
i,j:integer;
p:pchar;
t:AnsiString;
a16int:integer;
a16char:AnsiString;
begin
s:='';
i:=1;
//26044 236 ;182
while i< length(str) do begin
t:= str[i] + str[i+1];
a16int := hextoint2(t); //
// a16int := 26044;
// a16int := hextoint('ECB6');//
// a16char := chr(a16int);
if a16int <> 0 then
begin
a16char := ANSICHAR(a16int);
s:= s + a16char;
end;
// s := #$EC + #$B6;
// s := #236 + #182;
// s := chr(236) + chr(182);
i:=i+2;
end;
result:=s;
end;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。