|
将二进制数据以十六进制字符串形式输出的Delphi代码示例
- procedure OutputStructData(const MyData: Pointer);
- var
- Stream: TMemoryStream;
- HexString: string;
- i: Integer;
- begin
- Stream := TMemoryStream.Create;
- try
- Stream.WriteBuffer(MyData^, SizeOf(TMyStruct));
- SetLength(HexString, Stream.Size * 2);
- BinToHex(Stream.Memory^, PChar(HexString), Stream.Size);
- WriteLn('结构体数据流 (十六进制):');
- WriteLn(HexString);
- finally
- Stream.Free;
- end;
- end;
复制代码
在这个代码中,内存流中的二进制数据被转换为十六进制字符串,以便以更可读的格式输出。
|
|