急!!送分啦。。。16进制ASCII码转换成16进制数的问题?

szjiangyan 2003-08-20 09:06:52
如:16进ASCII码:35H 44H 转换成 5DH
33H 31H 转换成 31H
30H 30H 转换成 00H
...全文
203 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenzf 2003-08-20
  • 打赏
  • 举报
回复
GOOD!
firstshine 2003-08-20
  • 打赏
  • 举报
回复
function TForm1.Convert(sSource: String): String;
Const
MinBase = 2;
MaxBase = 36;

function StrToNum (const s: string; base: Integer;
neg: Boolean; max: Integer): Integer;
var
negate, done: Boolean;
i, len, digit, mmb: Integer;
c: Char;
mdb, res: Integer;
begin
res:= 0; i:= 1; digit:= 0;
if (base >= MinBase) and (base <= MaxBase) then
begin
mmb:= max mod base;
mdb:= max div base;
len:= Length (s);
negate:= False;
while (i <= len) and (s[i] = ' ') do Inc (i);
if neg then
begin
case s[i] of
'+': Inc (i);
'-': begin Inc (i); negate:= TRUE; end;
end; (* CASE *)
end; (* IF neg *)
done:= len > i;
while (i <= len) and done do
begin
c:= Upcase (s[i]);
case c of
'0'..'9': digit:= ORD(c) - 48;
'A'..'Z': digit:= ORD(c) - 55;
else
done:= FALSE
end; (* CASE *)
done:= done and (digit < base);
if done then
begin
done:= (res < mdb) or ((res = mdb) and (digit <= mmb));
IF done then
begin
res:= res * base + digit;
Inc (i);
end; (* IF done *)
end; (* IF done *)
end; (* WHILE *)
if negate then res:= - res;
end; (* IF done *)
Result:= res;
end;
var
iPos,iTemp:Integer;
sTemp:String;
begin
Result:='';
sSource:=Trim(sSource);
While sSource>'' do
begin
iPos:=Pos('H',sSource);
if iPos<=0 then Break;

sTemp:=Trim(Copy(sSource,1,iPos-1));
sSource:=Trim(Copy(sSource,iPos+1,Length(sSource)));
iTemp:=StrToNum(sTemp,16,false,MaxInt);
Result:=Result+Chr(iTemp);
end;
Result:=Result+'H';
end;
wweijie 2003-08-20
  • 打赏
  • 举报
回复
先将16进制ASCII码转换成通常的字符串,然后使用strtoint转换成数字,再将这些十进制数字转换成16进制

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧