十六进制数转为字符串-创新互联
//-----------------------------------------------
//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;
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页标题:十六进制数转为字符串-创新互联
URL链接:http://ybzwz.com/article/gpoeh.html