All pastes #267252 Raw Edit

Something

public text v1 · immutable
·published 2006-12-04 18:51 UTC
rendered paste body
function BinHex2Str(sHex: String): String;
var
  s, t: Integer;

  function MakeChar(cHexHi: Char; cHexLo: Char): Char;
  var
    nByteHi,
    nByteLo: Byte;
    nByte: Byte;
  begin
    if cHexHi >= 'A' then
      nByteHi := 10 + Ord(cHexHi) - Ord('A')
    else
      nByteHi := 0 + Ord(cHexHi) - Ord('0');

    if cHexLo >= 'A' then
      nByteLo := 10 + Ord(cHexLo) - Ord('A')
    else
      nByteLo := 0 + Ord(cHexLo) - Ord('0');

    nByte := (nByteHi shl 4) or nByteLo;
    Result := Char(nByte);
  end;
  
begin
  sHex := UpperCase(sHex);
  SetLength(Result, Length(sHex) div 2);

  s := 1;
  t := 1;
  repeat
    Result[t] := MakeChar(sHex[s], sHex[s + 1]);

    Inc(s, 2);
    Inc(t);
  until s > Length(sHex);
end;