Hex with Delphi

Could anyone tell me how to covert Hex to String ?
Thanks

Comments

  • : Could anyone tell me how to covert Hex to String ?
    : Thanks
    :
    Here is an untested function to convert a Hex to integer, then you can use IntToStr.
    [code]
    function HexToInt(Hex: string): integer;
    const
    HexValues='0123456789ABCDEF';
    begin
    Result := 0;
    if Length(Hex) > 8 then
    raise EConvertError.CreateFmt('%s is to large to convert!', [Hex]);
    while Hex <> '' do begin
    if Pos(Hex[1], HexValues) > 0 then
    Result := Result * 16 + Pos(Hex[1], HexValues) - 1
    // Multiply current Result with 16 and add next hex-digit
    else
    raise EConvertError.CreateFmt('%s is not a hex-digit!', [Hex[1]]);
    Delete(Hex, 1, 1); // Remove processed digit
    end;
    end;
    [/code]
    I hope this is what you meant by converting hex to string.
  • : Could anyone tell me how to covert Hex to String ?

    What exactly do you mean by converting hex to string? Since a hexadecimal number may contain the letters A through F, it already is a string.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories