Message Board


Message Board > Fenix / Bennu / Gemix / DIV > Base Conversion

April 12, 2007, 19:02
Imerion
None
19 posts

I tried to create a simple function in Fenix which converts numbers from different bases. So you could call it somewhat like this : "BaseConvert(Number,Base);" but I could not get any of the routines I had to work in Fenix. (Due to lack of certain commands). So what I wonder is, how to do this in Fenix? If someone could help me create such a function/process It would be a great help!
____________
Try my games : http://gamejolt.com/profile/imerion/5288
#
April 12, 2007, 19:16
Eckolin
Quite Whiskered
388 posts

I suppose I could do that.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
April 12, 2007, 19:59
Eckolin
Quite Whiskered
388 posts

Programmers excuse #3: (Well, it works on my pc...):

Code:
program because_I_can;
global
    string symbols = "0123456789ABCDEF";
    string test;
    int test2;
begin
    decToBase(16,2,&test);
    frame;
    write(0,20,20,3,test);
    test2=baseToDec("FA",16);
    write_int(0,20,40,3,&test2);
    while (!key(_esc))
        frame;
    end
end

string decToBase(int a, int b, string pointer s); // Decimal number, base of new representation, return string pointer.
private
    string result;
    int c=0;
    int d=0;
begin
    if (b>16) *s="";return;end
    if (b<=1) *s="";return;end
    while (a=>pow(b,c+1))
        c++;
    end
    while (c>=0)
        d=0;
        while (a>=(pow(b,c)*(d+1)))
            d++;
        end
        result=result+symbols[d];
        a-=pow(b,c)*d;
        c--;
    end
    *s=result;
    return;
end

int baseToDec(string a, int b);
private
    int result=0;
    int c;
    int d;
begin
    a=ucase(a);
    for (c=0;c<len(a);c++)
        d=find(symbols,a[c]);
        result+=d*pow(b,len(a)-c-1);
    end
    return result;
end

____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#

Message Board > Fenix / Bennu / Gemix / DIV > Base Conversion

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!