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;

转换时还需要注意16进制高低位的问题!高位在前或者低位在前需要分清楚!

猜你喜欢

转载自www.cnblogs.com/jeremywucnblog/p/11610930.html