Delphi: convert TByte to corresponding Hex value in AnsiString

I am trying to infer the value of TByte as its corresponding hexadecimal representation in AnsiString.

Example: TByte - 0x4F AnsiString: "4F" (two characters, a 4 and F)

I know the StringOf function, but converts it to a "displayed" character.

Is there any decent feature, or does anyone have a good idea how to quickly implement this?

Thank you in advance :)

+3
source share
2 answers

I would pass it to the byte and pass it to SysUtils.IntToHex.

+10
source

, Turbo Pascal SysUtils Hex .

, Delphi D2010 format:

lByteAsHex := format('%.2x',[AByte]);

.2 Precision , .

:

lIntAsHex = format('%x',[AInt]);

( int64), , format(%x,[10]) 'A', format('%.2x',[10] '0A'

0

Source: https://habr.com/ru/post/1759114/


All Articles