10进制与16进制之间的转换 delphi
delphi中有直接把10進制轉換成16進制的函數(shù):
??function ??IntToHex(Value: ??Integer; ??Digits: ??Integer): ??string; ??overload; ?
??function ??IntToHex(Value: ??Int64; ??Digits: ??Integer): ??string; ??overload;
使用方法為:
procedure ??TForm1.Button1Click(Sender: ??TObject);??
var ?
??????i,m: ??Integer;???
begin???
???Label1.Caption ??:= ??'';???
???for ??i ??:= ??1??to??Length(Edit1.Text)??do???
???begin
??????m :=??StrToInt(Edit1.Text[i]));?????
??????edit2 := IntToHex(StrToInt(Edit1.Text[i]),2)+ '';???
??????edit3 := IntToHex(m,2);????????
???end;???
end;
?
然而,delphi中卻沒有把16進制直接轉換成10進制的函數(shù),將16進制轉換成10進制需要自己定義函數(shù),這是自己編寫的一個,不當之處還請指出:
function HexToInt (str:string) : word;
var
???i , value : word;
???pos : word;
begin
???value:=0;
???pos:=length(str);
???for i:=1 to pos??do
???begin
??????case str[i] of
??????'f','F':
??????????????value := value*16+15;
??????'e','E':
??????????????value := value*16+14;
??????'d','D':
??????????????value := value*16+13;
??????'c','C':
??????????????value := value*16+12;
??????'b','B':
??????????????value := value*16+11;
??????'a','A':
??????????????value := value*16+10;
??????'0'..'9':
??????????????value := value*16+ord(str[i])-ord('0');
??????else
?????????result:=value;
?????????exit;
??????end;
???result:=value;
??end;
?
end;
轉載于:https://www.cnblogs.com/xtfnpgy/p/9285367.html
總結
以上是生活随笔為你收集整理的10进制与16进制之间的转换 delphi的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [译] Service workers:
- 下一篇: codeforces-73C. Lion