{$MODE OBJFPC}{$LONGSTRINGS ON}

uses
  SysUtils;

  function StringToSmallInt(APointer: Pointer): SmallInt;
  var
    ResBytes: packed array [0 .. 1] of Byte absolute Result;
    RawValue: AnsiString;
  begin
    RawValue := PAnsiChar(APointer);

    ResBytes[0] := StrToInt(Copy(RawValue, 5, 3));
    ResBytes[1] := StrToInt(Copy(RawValue, 1, 3));
  end;

  function SmallIntToString(APointer: Pointer): AnsiString;
  var
    ValBytes: packed array [0 .. 1] of Byte;
  begin
    ValBytes[0] := PByte(APointer + 1)^;
    ValBytes[1] := PByte(APointer + 0)^;

    Result := Format('$%2.2x $%2.2x', [ValBytes[0], ValBytes[1]]);
  end;

var
  StrValue: AnsiString = '$0D $33';
  IntValue: SmallInt;
begin
  WriteLn('Input:  "', StrValue, '"');

  IntValue := StringToSmallInt(PChar(StrValue));
  StrValue := SmallIntToString(@IntValue);

  WriteLn('Output: "', StrValue, '"');
end.