How about this?
[syntax="qbasic"]
'Omni-base converter
'Peter O'Rourke (Marinedalek) 2004
DECLARE FUNCTION reverse$ (text$)
DECLARE FUNCTION baseconv$ (basefrom%, baseto%, numfrom$)
DIM SHARED digitarray AS STRING * 36
digitarray = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
CLS
PRINT baseconv$(16, 2, "FFFF")
FUNCTION baseconv$ (basefrom%, baseto%, numfrom$)
IF baseto% <= 1 OR basefrom% < 1 OR baseto% > 36 OR basefrom% > 36 THEN baseconv$ = "0": EXIT FUNCTION
FOR position% = LEN(numfrom$) TO 1 STEP -1
tempdec& = tempdec& + (basefrom% ^ (LEN(numfrom$) - position%)) * (INSTR(digitarray, MID$(numfrom$, position%, 1)) - 1)
NEXT position%
IF baseto% = 10 THEN
baseconv$ = LTRIM$(STR$(tempdec&)) 'skip last calculation if destination is
'decimal - it 'd be a waste of time.
ELSE
DO
tempdest$ = MID$(digitarray, (tempdec& MOD baseto%) + 1, 1) + tempdest$
tempdec& = tempdec& \ baseto%
LOOP UNTIL tempdec& = 0
baseconv$ = tempdest$
END IF
END FUNCTION
FUNCTION reverse$ (text$)
FOR i% = LEN(text$) TO 1 STEP -1
temptxt$ = temptxt$ + MID$(text$, i%, 1)
NEXT i%
reverse$ = temptxt$
END FUNCTION
[/syntax]
Any feedback?
8% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.