' Conv2Dec.bas hh Aug. 14/02 ' convert 1 to 4 digit numbers in bases 2 to 9, to decimal ' an option is to add 1 to the number after it is converted DEFINT A-Z false = 0: true = NOT false addflag = false: CLS PRINT "Conv2Dec.bas Convert Numbers to Decimal hh 8/14/02" LOCATE 25, 10: PRINT "Enter a 5 digit number to exit program"; LOCATE 4, 1 10 INPUT "Enter the base of the numbers you wish to convert to decimal (2 - 9) "; basenum IF basenum < 2 OR basenum > 9 THEN GOTO 10 PRINT : PRINT "Do you wish to automatically add 1 to the number after conversion to decimal" INPUT "Press 'Y' or 'Enter"; addflag\$ IF addflag\$ = "y" OR addflag\$ = "Y" THEN addflag = true DO 20 PRINT "Enter the base "; basenum; " number "; INPUT test test\$ = STR\$(test) FOR i = 1 TO LEN(test\$) ' test for maximum digit size x\$ = MID\$(test\$, i, 1): x = VAL(x\$) ' extract digit IF x > basenum - 1 THEN ' the digit is too large for the base PRINT "** A digit is too large for the base **": GOTO 20 END IF NEXT i IF LEN(test\$) = 6 THEN END ' exit program (5 digits + leading space) IF LEN(test\$) = 4 THEN GOTO short ' leading zero or just 3 digits IF LEN(test\$) = 3 THEN GOTO shorter ' 2 leading zeros or just 2 digits IF LEN(test\$) = 2 THEN GOTO realshort ' 3 leading zeros or just 1 digit w\$ = MID\$(test\$, 2, 1): w = VAL(w\$) ' extract MSD from 4 digit number x\$ = MID\$(test\$, 3, 1): x = VAL(x\$) ' extract Middle digit y\$ = MID\$(test\$, 4, 1): y = VAL(y\$) ' extract next Middle digit z\$ = MID\$(test\$, 5, 1): z = VAL(z\$) ' extract LSD GOTO outer short: w = 0 x\$ = MID\$(test\$, 2, 1): x = VAL(x\$) ' extract MSD y\$ = MID\$(test\$, 3, 1): y = VAL(y\$) ' extract Middle digit z\$ = MID\$(test\$, 4, 1): z = VAL(z\$) ' extract LSD GOTO outer shorter: w = 0 x = 0 y\$ = MID\$(test\$, 2, 1): y = VAL(y\$) ' extract Middle digit z\$ = MID\$(test\$, 3, 1): z = VAL(z\$) ' extract LSD GOTO outer realshort: w = 0 x = 0 y = 0 z\$ = MID\$(test\$, 2, 1): z = VAL(z\$) ' extract LSD outer: IF addflag THEN PRINT " Base"; basenum; test; " plus 1 = Decimal"; ELSE PRINT " Base"; basenum; test; " = Decimal"; END IF result = w * basenum * basenum * basenum + x * basenum * basenum + y * basenum + z IF addflag THEN PRINT result + 1 ELSE PRINT result LOOP