Delphi – 10进制16进制相互转换

10进制转16进制

使用IntToHex可以实现十进制到十六进制的转换,注意这里的参数有两个,第一个表示需要被转换的10进制数,第二个表示转换后用几位来显示16进制数。

代码如下:

 

function OctToHex(iValue, iBit: Integer): String; 
begin 
  Result := IntToHex(iValue, iBit);
end;

16进制转10进制

使用StrToInt可以实现16进制到10进制的转换。

代码如下:

function HexToOct(hValue: String): Integer; 
begin 
  Result := StrToInt('$' + hValue); 
end;

 

发表回复

登录... 后才能评论