I suspect you want a function that takes an array of bytes (or a raw pointer to bytes) and returns a string containing the data in hexadecimal form.
I always use the following routine of mine to do this:
function BytesToString(ABuf: PByte; ALen: Cardinal): string; overload;
const
HexDigits: array[0..$F] of Char = '0123456789ABCDEF';
var
i: Integer;
begin
if ALen = 0 then
begin
Result := '';
Exit;
end;
SetLength(Result, 3 * ALen - 1);
Result[1] := HexDigits[ABuf^ shr 4];
Result[2] := HexDigits[ABuf^ and $0F];
for i := 1 to ALen - 1 do
begin
Inc(ABuf);
Result[3*i + 0] := ' ';
Result[3*i + 1] := HexDigits[ABuf^ shr 4];
Result[3*i + 2] := HexDigits[ABuf^ and $0F];
end;
end;
type
TByteArray = array of Byte;
function BytesToString(ABytes: TByteArray): string; overload;
begin
Result := BytesToString(PByte(ABytes), Length(ABytes));
end;
The first overload takes a raw pointer and a length, while the second overload takes a dynamic array of bytes.
This is a very fast implementation, since I do not use string concatenation (which requires constant heap reallocations).
The above code was written specifically for the old Delphi 7 compiler and RTL. A modern version would look more like this:
function BytesToString(ABuf: PByte; ALen: Cardinal): string; overload;
const
HexDigits: array[0..$F] of Char = '0123456789ABCDEF';
var
i: Integer;
begin
if ALen = 0 then
Exit('');
SetLength(Result, 3 * ALen - 1);
Result[1] := HexDigits[ABuf[0] shr 4];
Result[2] := HexDigits[ABuf[0] and $0F];
for i := 1 to ALen - 1 do
begin
Result[3*i + 0] := ' ';
Result[3*i + 1] := HexDigits[ABuf[i] shr 4];
Result[3*i + 2] := HexDigits[ABuf[i] and $0F];
end;
end;
function BytesToString(ABytes: TArray<Byte>): string; overload;
begin
Result := BytesToString(PByte(ABytes), Length(ABytes));
end;
The above code groups each byte using a space character. Of course, you might not want that, but doing it without grouping is a simpler task, so I'll leave that as an exercise.