I made some hex functions and i thought that maybe someone needs them! The $ is only usefull for scar, for example: bla := 10;(Integer) bla := $A;(Hex).
Newer:
Old:Code:program Hex;
function HexToInt(hex : String): Integer;
var
Bla : String;
begin;
Bla := '$' + TrimOthers(Hex);
Result := StrToInt(Bla);
if pos('-',hex) >0 then result :=-result;
end;
function IntToHex(int : integer): string;
var
Hexx : string;
Bla : integer;
begin;
Hexx := '0123456789ABCDEF';
Bla := iAbs(int);
while not (bla div 16 = 0) do
begin;
result := Hexx[bla mod 16 + 1] + result;
bla := bla div 16;
end;
if int < 0 then result := '-$' + Hexx[bla+1] + result
else result := '$' + Hexx[bla+1] + result;
end;
begin
Writeln('The $ is for scar, not for the hex number itself! - MastaRaymond');
Writeln(IntToHex(16777215));
Writeln(IntToStr(HexToInt('$FFFFFF')));
end.
Code:program New;
function ConvertHex(Hex : string) : integer;
begin;
case lowercase(Hex) of
'a': result := 10;
'b': result := 11;
'c': result := 12;
'd': result := 13;
'e': result := 14;
'f': result := 15;
end;
if StrToIntDef(Hex,11) < 10 then Result := StrToInt(Hex);
end;
function HexToInt(hex : String): Integer;
var
Bla : String;
I,J : Integer;
begin;
Bla := TrimOthers(Hex);
J := Length(Bla);
For I := 0 to Length(Bla)-1 do
Result := Result +(Round(Pow(16,I)) * ConvertHex(Bla[J-I]));
if pos('-',hex) >0 then result :=-result;
end;
function ConvertInt(Int : Integer): string;
begin;
case Int of
10: result := 'A';
11: result := 'B';
12: result := 'C';
13: result := 'D';
14: result := 'E';
15: result := 'F';
end;
if Int < 10 then Result := inttostr(Int);
end;
function IntToHex(int : integer): string;
var
Bla : integer;
begin;
Bla := iAbs(int);
while not (bla div 16 = 0) do
begin;
result := convertInt(bla mod 16) + result;
bla := bla div 16;
end;
result := convertInt(bla) + result;
if int < 0 then result := '-' + result;
result := '$' + result;
end;
begin
Writeln('The $ is for scar, not for the hex number itself! - MastaRaymond');
Writeln(IntToHex(16238230));
Writeln(IntToStr(HexToInt('$F7C696')));
end.

