1.官方的IdGlobal中有这个方法

//IPv4 address conversion
function ByteToHex(const AByte: Byte): string;
{$IFDEF USE_INLINE}inline;{$ENDIF}
begin
SetLength(Result, 2);
Result[1] := IdHexDigits[(AByte and $F0) shr 4];
Result[2] := IdHexDigits[AByte and $F];
end;

算了, 以后还是用delphi 官方的东西吧 效率 和升级什么的有保障

 

2.第三方搜索的(注意返回的shortstring可直接该用string):

{Convert Byte to HEX string}
function ByteToHex(InByte:byte):shortstring;
const Digits:array[0..15] of char='0123456789ABCDEF';
begin
result:=digits[InByte shr 4]+digits[InByte and $0F];
end;
Description 
This is a function that converts a Byte into a string containing the number's hexadecimal (base 16)
representation.InByte is the number which we want to convert.



Example :

MyHex := ByteTohex($FF);
the result
MyHex is "FF".

MyHex := ByteTohex(255);
the result
MyHex is "FF".

MyHex := ByteTohex($55);
the result
MyHex is "55".
posted on 2012-03-01 23:34  del88  阅读(79)  评论(0编辑  收藏  举报