Autor Beitrag
Ice
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 03.02.03 10:29 
Hallo Leute,

ich möchte gerne einen String mit hexadezimalen Zahlen in einen String mit dezimal Zahlen umwandeln, bzw. umgekehrt.
Kennt da jemand nen Algorithmus??

Vielen Dank schonmal....

Ice
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mo 03.02.03 10:37 
Hallo,

Dezimal in Hex:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
uses
  SysUtils;

var s:String;

  ...
  s:=IntToHex(255, 2);
  ...


Hex in Dezimal:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
uses
  Math;

function HexCharToWert(CharWert:Char):Integer;
begin
  case CharWert of
    'A'..'F':Result:=Ord(CharWert)-65+10;
    else Result:=StrToInt(CharWert);
  end; // case
end; // HexCharToWert


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

...
...
var s:String;

  ...
  s:=IntToStr(HexToInt('FF'));
  ...

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)


Zuletzt bearbeitet von smiegel am Mo 03.02.03 10:48, insgesamt 1-mal bearbeitet
Ice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114



BeitragVerfasst: Mo 03.02.03 10:43 
Alles klar,
genau sowas hatte ich gesucht , vielen Dank!!

Ice
Brueggendiek
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 304

Win 98, Win98SE, Win XP Home
D5 Std
BeitragVerfasst: Mo 03.02.03 18:20 
Hallo!

@smiegel: bitte lege die Beißzange zurück in den Werkzeugkasten, da gehört sie hin! :wink:

Einen Hex-String kann man ganz einfach mit
ausblenden Quelltext
1:
zahl := StrToInt('$'+hexwert);					

in eine Zahl umwandeln, da braucht man keine Funktion für!
Man kann im Source ja auch z.B. $0D0A schreiben, der Compiler wandelt das dann auch um.

Gruß

Dietmar Brüggendiek