* * ConvertBase program * Tony Gravagno, Nebula Research and Development * http://Nebula-RnD.com * * Open Source v1.0 for D3 : 05 feb 2003 * Originally written : 06 jan 2000 * * Please e-mail comments, enhancements, and other platform-specfic * versions to Freeware@Nebula-RnD.com. * * Updates may be available at http://Nebula-Rnd.com/freeware * * Program comments are at the very bottom of the code. * * Responsibility for implementation and use of this program rests * entirely with the user. Nebula R&D will not be liable for any * time, data, financial, or other loss incurred as a result of * execution of this program. This software is distributed as-is * with no warranties or guarantees, explicit or implied. * * This program will convert any base to any other base. * Assume bases are from 2 to 36 * chars = "0123456789" chars := "abcdefghijklmnopqrstuvwxyz" * add more here if you dare. print "base from "; input base.from print "base to "; input base.to print "number "; input num.from original.from = num.from if base.from # 10 then gosub from.n.to.decimal gosub from.decimal print original.from:" in base ":base.from:" = " print num.to:" in base":base.to stop from.decimal: * hold = "" divisor = num.from loop rem.int = int(divisor / base.to) rem.mod = mod( divisor , base.to ) divisor = rem.int hold<-1> = rem.mod until divisor = 0 do repeat digits = dcount(hold,@am) num.to = "" for n = digits to 1 step -1 num.to := chars[ hold+1 , 1 ] next n return from.n.to.decimal: * digits = len( num.from ) num.to = 0 for n = 1 to digits digit = num.from[ n , 1 ] multiplier = index( chars , digit, 1 ) - 1 exponent = digits - n hold = multiplier * ( base.from ** exponent ) num.to += hold next n num.from = num.to return * * * END * * Comments * If you make enhancements or port this code to another platform, * please send the code back to Tony Gravagno so that everyone benefits. * * This code is all in lower case so far, so it will only work on D3. *