Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Object-Pascal / Delphi-Language (https://www.delphipraxis.net/35-library-object-pascal-delphi-language/)
-   -   Delphi HexToInt (https://www.delphipraxis.net/3526-hextoint.html)

janjan 17. Mär 2003 09:22


HexToInt
 
Komischerweise enthält Delphi zwar eine Funktionzur Umwandlung von Integer in Hex-Strings, eine Rückwandlung ist nicht vorgesehen. Nachdem ich mir sowas selber geschrieben habe, bin ich zufällig auf eine viel einfachere Lösung gestoßen:

Delphi-Quellcode:
function HexToInt(HexNum: string): LongInt;
begin
  Result:=StrToInt('$' + HexNum);
end;
---

Folgender Code ist noch von Clane "eingereicht" worden:
Delphi-Quellcode:
uses
Math;

function HexToInt(const HexWert:String):Integer;
var i:Integer;
s:String;
begin
Result:=0;
s:=UpperCase(HexWert);
for i:=1 to Length(s) do if (Ord(s[i]) in [0..47, 58..64, 71..255]) then
begin
Result:=-1;
Break;
end; // for i
if (Result=0) then for i:=0 to Length(s)-1 do
Result:=Result+(HexCharToWert(s[Length(s)-i])*Round(Power(16, i)));
end; // HexToInt
[edit=flomei]Clanes Quelltext hinzugefügt. Mfg, flomei[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz