Results 1 to 9 of 9

Thread: IntToHex & HexToInt

  1. #1
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default IntToHex & HexToInt

    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:
    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.
    Old:
    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.
    Verrekte Koekwous

  2. #2
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ?what it does im not that good on english what is hex?
    ~Hermen

  3. #3
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by hermpie View Post
    ?what it does im not that good on english what is hex?
    Hex is a different way to write numbers, decimals (what we use) has got the digits [0,1,2,3,4,5,6,7,8,9], hex has got the digits [0,1,2,3,4,5,6,7,8,9,A(10),B(11),C(12),D(13),E(14), F(15)]. Because were used to Decimals, Hex is hard to read, without converting it. So if you want to protect your 'Numbers' in a script (*Cough* Wizzup's Draynor Fisher), you can use this function to find the Hex, but thats not the reason why i made this. You will find out.. soon?

    ~Raymond
    Verrekte Koekwous

  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Haha, in MSI I saw in wizzups fish finding function him using hex

  5. #5
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by mastaraymond View Post
    Hex is a different way to write numbers, decimals (what we use) has got the digits [0,1,2,3,4,5,6,7,8,9], hex has got the digits [0,1,2,3,4,5,6,7,8,9,A(10),B(11),C(12),D(13),E(14), F(15)]. Because were used to Decimals, Hex is hard to read, without converting it. So if you want to protect your 'Numbers' in a script (*Cough* Wizzup's Draynor Fisher), you can use this function to find the Hex, but thats not the reason why i made this. You will find out.. soon?

    ~Raymond
    You can just inttostr a hex...

    WriteLn(IntToStr($43));

    Plus, windows calculator extended for Hex <> Bin <> Dec..



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  6. #6
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    sort encrytion you can make a author on a script?
    ~Hermen

  7. #7
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    SCAR Code:
    program Hex;

    function IntToHex(Int: Integer): string;
    var
      i: Integer;
      Hex: string;
    begin;
      Hex := '0123456789ABCDEF';
      i := iAbs(Int);
      while not (i div 16 = 0) do
      begin;
        Result := Hex[i mod 16 + 1] + Result;
        i := i div 16;
      end;
      Result := Hex[i + 1] + Result;
    end;

    function HexToInt(Hex: string): Integer;
    var
      s: string;
    begin;
      s := Trim(Hex);
      if not (Hex[1] = '$') then s := '$' + s;
      Result := StrtoInt(s);
    end;

    begin
      Writeln(IntToHex(16238230));
      Writeln(IntToStr(HexToInt('F7C696')));
    end.
    Shorter...

  8. #8
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Hehe. Thats shorter, but it doesnt work for minus numbers .

    EDIT: /Me wins :
    SCAR 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.
    Verrekte Koekwous

  9. #9
    Join Date
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    ok Hex to normal, i know it was possible with a simple writeln, but it's cool i can use the other way now
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •