Base Conversion

Gerald G. Noser Huntington Beach, California

This is a BASIC computer program that I have written for base conversion. It allows for the entry of a number in any base (2 through 16) and will calculate and print the equivalent value in a new base as specified by the user (again, 2 through 16). The allowable place holders (digits) of 0-9 and A-F are held in a dimensioned string variable for comparison of the data entered. A maximum value of 10,000,000 (base 10) has been set for the initial data entry.

All appropriate instructions, checks for the data entered and error messages are included within the program. It should be noted that bases larger than sixteen may be accommodated by adjusting the READ/DATA loop of lines 30 and 40 and also editing the checks for the maximum values of Bl# and B2# in lines 120 and 150.

This program was written for a non-disk Level II Model I system.

i 13 REM BASE CONVERSION! SUBMITTED BY GERALD G. NOSER 20 CLEAR 500

¡REM IN IT BASE TEN AND MAX VALUES 60 PR I NTS 128) CHR$(30)"ENTER THE NUMBER TO BE CONVERTED" 70 PRINT825G t "(USE THE NUMERALS 0-9 AND/OR LETTERS /i-F ON

:PR [email protected] i 72 i! ¡INPUT N$ ¡PRINT ¡PRINT 90 IF N$ =" " THEN 50 ¡REM RE-ENTER N$ 00 Bl«=-1

:PRINT5256 t CHR$(30)"ENTER THE BASE OF THE NUMBER (2 TO IS)" 10 PR [email protected] 11 ¡INPUT Bl«

20 IF Bl#<2 OR B1 #> 16 OR Bl#OINT(Bl») THEN 100

:[email protected] CHR$(30)"ENTER THE NEW BASE VALUE (2 TO IS)" 40 [email protected] m ¡INPUT B2#

50 IF B2»<2 OR B2»>1S OR B2«OINT(BZ«) THEN 130

¡REM RE-ENTER B2# B0 NM$=N$ :Z=LEN(N$) ¡FOR X=1 TO Z 70 Y$=RIGHT$(N$ 11) ¡FOR Y = 1 TO IS

¡IF Y$ = X$(Y) THEN 210 ELSE NEXT Y 80 REM COMPARE RIGHT-MOST CHARACTER TO ALLOWABLE PLACE HOLDERS 90 PRINT05121 "*** ILLEGAL CHARACTER ON ENTRY. RE-ENTER, ***" 200 FOR Xs1 to 1000 ¡NEXT X ¡GOTO 50 210 Y# = Y-1

¡IF Y#>=B1# THEN 190 ¡REM CHARACTER WAS > = BASE VALUE 220 BT»=BT«+ INT(Y#*Bl«*(X-l)+,5) ¡REM INCREMENT BASE TEN VALUE 230 IF BT#>MVs THEN PRINT0512 •"*** NUMBER TOO LARGE RE-ENTER ***"

¡REM 'DROP' RIGHT-MOST CHARACTER OF STRING 250 NEXT X

¡IF B2*< >10 THEN 270 2G0 PRINTIB40 i NM$i" (BASE" ¡Bl«i") = "> BT«I"(BASE 10)"

¡REM NEW VALUE IN THE BASE B2# AS A STRING VARIABLE 280 R#=BT#-INT(BT#/B2#)*B2#

¡REM REMAINDER R# CONVERTED TO APPROPRIATE CHAR X$() FROM DATA LIST 300 IF BT«>0 THEN 280

310 [email protected] i NM$ i" (BASE" !B1*i") = "iNV$i" (BASE" iB2# !")" 320 X$=" "

:PRINTH7E8 i CHR$(30)"AGAIN (Y/N)" 330 PRINT07B3»; ¡INPUT >($

THEN 50

THEN 320 ELSE END

THEN 50

THEN 320 ELSE END

0 0

Post a comment