title: Converting Strings to Hex in a performant way
body: <p>I developed the following function to convert strings to hex values.</p>
  
  <pre><code>function StrToHex(const S: String): String;
  const
    HexDigits: array[0..15] of Char = '0123456789ABCDEF';
  var
    I: Integer;
    P1: PChar;
    P2: PChar;
    B: Byte;
  begin
  
    SetLength(Result, Length(S) * 2);
    P1 := @S[1];
    P2 := @Result[1];
  
    for I := 1 to Length(S) do
    begin
      B := Byte(P1^);
      P2^ := HexDigits[B shr 4];
      Inc(P2);
      P2^ := HexDigits[B and $F];
      Inc(P1);
      Inc(P2);
    end; 
  
  end; 
  </code></pre>
  
  <p>Now I was wondering whether there is a more efficient way to convert the strings?</p>