您好,登錄后才能下訂單哦!
//-----------------------------------------------
//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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。