先strtoint,把字符串转换成integer型,然后+1
再strtohex转换成16进制数,
strtohex代码如下:
function TForm1.strtohex(str: string): DWORD;
var
i,j,m : integer;
temp,k : DWORD;
begin
i:=length(str);
j:=1;k:=0;
while(j<i+1) do
begin
case str[j] of
'0'..'9':
begin
temp:=1;
for m:=1 to (i-j) do temp:=16*temp;
temp:=temp*DWORD(strtoint(str[j]));
k:=k+temp;
end;
'A'..'F':
begin
temp:=1;
for m:=1 to (i-j) do temp:=16*temp;
temp:=temp*DWORD(ord(str[j])-ord('A')+10);
k:=k+temp;
end;
'a'..'f':
begin
temp:=1;
for m:=1 to (i-j) do temp:=16*temp;
temp:=temp*DWORD(ord(str[j])-ord('a')+10);
k:=k+temp;
end;
else
begin
result:=0;
exit;
end;
end;
inc(j);
end;
result:=k;
end;