#### Howdy, Stranger!

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

# Hex with Delphi

Member Posts: 9
Could anyone tell me how to covert Hex to String ?
Thanks

• Member Posts: 6,349
: 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.
• Member Posts: 1,621
: 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.
• USAMember Posts: 4,624 ✭✭

___ < http://forcoder.org /> free video tutorials and ebooks about [ JavaScript PL/SQL Delphi Python MATLAB Visual Basic Objective-C Java Ruby C++ R C# PHP Perl Assembly Swift Scratch Visual Basic .NET Go C Logo COBOL D Apex Alice Bash Fortran SAS ML Scheme ABAP Rust Kotlin Ada LabVIEW VBScript Hack Transact-SQL Julia Lisp Scala FoxPro Clojure Lua Crystal F# Prolog Awk Dart Erlang ] _____