'===========================================================================
' Subject: BASE CONVERSION                    Date: 03-06-97 (20:24)       
'  Author: Van Anderson                       Code: QB, QBasic, PDS        
'  Origin: vanisaac@cport.com               Packet: ALGOR.ABC
'===========================================================================
' This program changes a given number into its equivalent in any base.
' It is really simple, but it is a good algorithm.  I used the convention
' created by Hex in assigning the value of a given letter (values 10-36).
' In looking at this program, you may notice that in order to solve the
' problem, I had to chang the numbers to strings in order to print them out.
' Van Anderson 2.10.1996
CLS
INPUT "Enter the number you want converted: ", num1$
num1$ = UCASE$(num1$)
INPUT "Enter the number's base: ", base1
INPUT "Enter the base you want it converted to: ", base2

N1 = 0
N2 = LEN(num1$)
DO UNTIL N1 = N2
        digit$ = RIGHT$(num1$, 1)
        digitascii = ASC(digit$)
        IF digitascii < 58 THEN
                dig = digitascii - 48
        ELSE
                dig = digitascii - 55
        END IF
        tempnum = tempnum + dig * base1 ^ N1
        N1 = N1 + 1
        num1$ = LEFT$(num1$, N2 - N1)
LOOP
num1 = tempnum
tempnum = 0
PRINT num1$; "In base"; base1; "Equals this number in base"; base2; ":"
DO UNTIL num1 = 0
        tempdig = num1 MOD base2
        IF tempdig > 9 THEN
                tempdig = tempdig + 55
                ELSE
                tempdig = tempdig + 48
                END IF
        tempchar$ = CHR$(tempdig)
        tempnum$ = tempchar$ + tempnum$
        num1 = num1 \ base2
LOOP
PRINT tempnum$
tempnum$ = ""
END
