Einzelnen Beitrag anzeigen

Schokohase
(Gast)

n/a Beiträge
 
#33

AW: Vermutlich Hex Daten Umwandeln

  Alt 3. Apr 2019, 23:32
Delphi-Quellcode:
program Project2;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils;

function BytesToHexView(const ABytes: TBytes): string;
var
  hex, str: string;
  idx, len, len2: Integer;
  b: Byte;
begin
  Result := string.Empty;
  len := Length(ABytes);
  hex := string.Empty;
  str := string.Empty;

  if len mod 16 = 0 then
    len2 := len
  else
    len2 := len + 16 - len mod 16;

  for idx := 1 to len2 do
  begin
    if idx <= len then
    begin
      b := ABytes[idx - 1];
      hex := hex + IntToHex(b, 2) + ' ';
      if b < 32 then
        str := str + '.'
      else
        str := str + Chr(b);
    end
    else
    begin
      hex := hex + ' ';
      str := str + ' ';
    end;
    if idx mod 16 = 0 then
    begin
      if not string.IsNullOrEmpty(Result) then
        Result := Result + sLineBreak;
      Result := Result + hex + '| ' + str;

      hex := string.Empty;
      str := string.Empty;
    end;
  end;
end;

begin
  try
    Writeln(BytesToHexView([ //
      $05, $03, $01, $01, $04, $02, $00, $00, $00, $00, $00, $00, $01, $01, $04, $02, //
      $00, $00, $00, $00, $00, $00, $01, $01, $04, $02, $00, $00, $00, $00, $00, $00, //
      $01, $01, $04, $02, $00, $00, $00, $00, $00, $00, $01, $01, $04, $02, $00, $00, //
      $00, $00, $00, $00, $01, $01, $04, $02, $00, $00, $00, $00, $00, $00, $01, $01, //
      $04, $02, $06, $00, $00, $00, $50, $00, $72, $00, $69, $00, $76, $00, $61, $00, //
      $74, $00, $00, $00, $02, $01, $00, $01, $FA, $B8, $8A, $42, $FB, $53, $48, $80]));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;

end.
Code:
05 03 01 01 04 02 00 00 00 00 00 00 01 01 04 02 | ................
00 00 00 00 00 00 01 01 04 02 00 00 00 00 00 00 | ................
01 01 04 02 00 00 00 00 00 00 01 01 04 02 00 00 | ................
00 00 00 00 01 01 04 02 00 00 00 00 00 00 01 01 | ................
04 02 06 00 00 00 50 00 72 00 69 00 76 00 61 00 | ......P.r.i.v.a.
74 00 00 00 02 01 00 01 FA B8 8A 42 FB 53 48 80 | t.......ú¸?BûSH?
  Mit Zitat antworten Zitat