Mike Halliday
04-20-2008, 09:32 AM
Here are 2 functions I've used in this months newsletter tutorial. Thought I would release them early.
I have tested them and they seem to work, but it is 20 years since I did any of this!! ha ha
func Hex2Dec(toConvert$)
Digits$ = "0123456789ABCDEF";
Base$ = 16;
Nbr$ = toConvert$;
NbrBase2$ = 0;
pwr$ = 0;
pwrrslt$ = 0;
ch$=0;
cl$ = 0;
atLen$ = Length(Nbr$);
For (chrLoop$, atLen$, 1, -1)
ch$ = INT(POS(MID(Nbr$, chrLoop$-1, 1), Digits$));
pwrrslt$ = POW(Base$, pwr$);
cl$ = (ch$ * pwrrslt$);
NbrBase2$ = (NbrBase2$ + cl$);
pwr$++;
end;
result$ = NbrBase2$;
return (result$);
end;
func Dec2Hex(toConvert$)
remaind$ = 0;
Digits$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Base$ = 16;
Nbr$ = toConvert$;
NbrBase2$ = "";
WHILE (NOT Nbr$ == 0)
remaind$ = RoundEX(Nbr$ MOD Base$,1);
NbrBase2$ = MID(Digits$, (Nbr$ MOD Base$) + 1, 1) % NbrBase2$;
Nbr$ = Nbr$ / Base$;
END ;
result$ = NbrBase2$;
return (result$);
end;
They are not clean or clevver, but you get the basic idea. Copy and paste them into your code and use as normal functions.
If you find problems with them, change them and re-post.
Enjoy
Mike.
I have tested them and they seem to work, but it is 20 years since I did any of this!! ha ha
func Hex2Dec(toConvert$)
Digits$ = "0123456789ABCDEF";
Base$ = 16;
Nbr$ = toConvert$;
NbrBase2$ = 0;
pwr$ = 0;
pwrrslt$ = 0;
ch$=0;
cl$ = 0;
atLen$ = Length(Nbr$);
For (chrLoop$, atLen$, 1, -1)
ch$ = INT(POS(MID(Nbr$, chrLoop$-1, 1), Digits$));
pwrrslt$ = POW(Base$, pwr$);
cl$ = (ch$ * pwrrslt$);
NbrBase2$ = (NbrBase2$ + cl$);
pwr$++;
end;
result$ = NbrBase2$;
return (result$);
end;
func Dec2Hex(toConvert$)
remaind$ = 0;
Digits$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Base$ = 16;
Nbr$ = toConvert$;
NbrBase2$ = "";
WHILE (NOT Nbr$ == 0)
remaind$ = RoundEX(Nbr$ MOD Base$,1);
NbrBase2$ = MID(Digits$, (Nbr$ MOD Base$) + 1, 1) % NbrBase2$;
Nbr$ = Nbr$ / Base$;
END ;
result$ = NbrBase2$;
return (result$);
end;
They are not clean or clevver, but you get the basic idea. Copy and paste them into your code and use as normal functions.
If you find problems with them, change them and re-post.
Enjoy
Mike.