!###########################################################################
! PROGRAM CONVRT This program will convert any input (within range)
! to HEX, BINARY, ASCII, DECIMAL, RAD50, and OCTAL
! values. Directions are provided during run-time.
!
! by DAVE HEYLIGER - AMUS STAFF
!
! last update: 09-11-85
!###########################################################################
THE'MAPS:
! Defining all variables used in CONVRT
!__________________________________________________________________________
MAP1 OP,S,16,""
MAP1 RAD'GUYS,S,40,"#ABCDEFGHIJKLMNOPQRSTUVWXYZ$.?0123456789"
MAP1 HEX'GUYS,S,16,"0123456789ABCDEF"
MAP1 OCT'GUYS,S,8,"01234567"
MAP1 DECIMAL,F !These are used for general
MAP1 DEC'SAV,F
MAP1 RAD50,S,6,"" !conversion equations.
MAP1 DIGIT,S,4,""
MAP1 CHAR'STRING,S,3,""
MAP1 CHAR'1,S,1,"" !The individual characters as
MAP1 CHAR'2,S,1,"" !they are found.
MAP1 CHAR'3,S,1,""
MAP1 I,F !Various counters etc.
MAP1 J,F
MAP1 CURSOR,F
MAP1 FLAG,F
MAP1 HEX'VAL,S,4
MAP1 OCT'VAL,S,6
MAP1 BIN'VAL,S,16
MAP1 ASC'VAL,S,4
MAP1 TMP'VAL,F
MAP1 BLANK,S,25," "
MAP1 BLANK2,S,50," "
MAP1 CNT,S,1,""
THE'TOP:
! Prints out the 'screen format' and that's about it
!___________________________________________________________
START: CURSOR = 0
START1:
! Consider this the 'clean screen' situation.
!_____________________________________________________________________
OP = ""
? TAB(20,20) "ENTER [CR] TO MOVE CURSOR TO APPROPRIATE BASE"
? TAB(21,21) "AND THEN ENTER IN WHAT YOU WANT CONVERTED."
GOTO MOVE'IT ! (MOVE'IT) simply moves the cursor to every base.
GET'IT:
! The logic here is as follows: if the user enters a decimal
! number, then the decimal number is used to calculate all of
! the equivalent numbers in every other base. If the user does
! NOT enter a decimal number, then the number (whatever base) is
! converted to decimal, then this decimal number is used just as
! if the user entered a decimal number to begin with.
!______________________________________________________________________
INPUT"", OP : IF CURSOR <> 3 THEN OP = UCS(OP) !NOT decimal number
IF OP = "" THEN GOTO MOVE'IT !Moves to next base
IF CURSOR = 4 THEN FLAG = 0 ELSE FLAG = 1 !A '0' means decimal
ON CURSOR GOTO H'D, B'D, A'D, D'D, R'D, O'D !Change base to dec.
H'D:
! Converts HEX to decimal
!_______________________________
DECIMAL = 0 : J = 0
FOR I = LEN(OP) TO 1 STEP -1
J = J + 1
DECIMAL = DECIMAL +((INSTR(1,HEX'GUYS,(MID$(OP,J,1)))-1) *(16**(I-1)))
NEXT I
GOTO D'D
B'D:
! Converts binary to decimal
!__________________________________
DECIMAL = 0 : J = 0
FOR I = LEN(OP) TO 1 STEP -1
J = J + 1
IF MID$(OP,J,1) = "1" THEN DECIMAL = DECIMAL + 2**(I-1)
NEXT I
GOTO D'D
A'D:
! Converts a SINGLE character to decimal ASCII value.
! If it is THREE characters, then it's a job for RAD50.
!___________________________________________________________
IF LEN(OP) > 1 THEN GOTO RAD'50
DECIMAL = ASC (OP)
GOTO D'D
R'D:
! Converts a RAD50 number into the three characters and only
! the RAD50 number and these characters are displayed.
!___________________________________________________________________
IF OP = "177777" THEN DIGIT = ":80" : GOTO P'D
RAD50 = RIGHT$(("000000"+OP),6)
DECIMAL = 0
I = 1
J = 5
II:
DIGIT = MID$(RAD50,I,1)
Y = VAL(DIGIT) * 8 ** J
DECIMAL = DECIMAL + Y
J = J - 1
I = I + 1
IF J >= 0 THEN GOTO II
O'D:
! Converts an octal number to the decimal equivalent
!_________________________________________________________
J = 0 : DECIMAL = 0
FOR I = LEN(OP) TO 1 STEP -1
J = J + 1
DECIMAL = DECIMAL + VAL(MID$(OP,J,1))*(8**(I-1))
NEXT I
D'D:
! Takes the decimal value entered (or calculated above) and
! finds the values for each possible base
!________________________________________________________________
IF FLAG = 0 THEN DECIMAL = VAL(OP)
DEC'SAV = DECIMAL
TO'HEX:
HEX'VAL = ""
FOR I = 4 TO 1 STEP -1
TMP'VAL = INT(DECIMAL / 16**(I-1))
DECIMAL = DECIMAL - TMP'VAL*16**(I-1)
HEX'VAL = HEX'VAL + MID$(HEX'GUYS,(TMP'VAL+1),1)
NEXT I
TO'OCT:
OCT'VAL = "" : DECIMAL = DEC'SAV
FOR I = 6 TO 1 STEP -1
TMP'VAL = INT(DECIMAL / 8**(I-1))
DECIMAL = DECIMAL - TMP'VAL*8**(I-1)
OCT'VAL = OCT'VAL + MID$(OCT'GUYS,(TMP'VAL+1),1)
NEXT I
TO'BIN:
BIN'VAL = "" : DECIMAL = DEC'SAV
FOR I = 16 TO 1 STEP -1
TMP'VAL = INT(DECIMAL / 2**(I-1))
DECIMAL = DECIMAL - TMP'VAL*2**(I-1)
IF TMP'VAL = 1 THEN BIN'VAL = BIN'VAL + "1" &
ELSE BIN'VAL = BIN'VAL + "0"
NEXT I
RAD'50:
! This portion of the prg is used only if THREE characters were
! entered by the user. It calculates the RAD50 equivalent.
!_____________________________________________________________________
CHAR'STRING = UCS(OP)
IF OP = ":80" THEN RAD50 = "177777" : GOTO P'RAD
I = (INSTR(1,RAD'GUYS,MID$(CHAR'STRING,1,1)) - 1)*1600
J = (INSTR(1,RAD'GUYS,MID$(CHAR'STRING,2,1)) - 1)*40
K = INSTR(1,RAD'GUYS,MID$(CHAR'STRING,3,1)) - 1
DECIMAL = I + J + K
RAD50 = ""
LOOP:
Y = INT(DECIMAL/8)
DIGIT = STR$(DECIMAL - (Y * 8))
RAD50 = DIGIT + RAD50
DECIMAL = Y
IF DECIMAL # 0 THEN GOTO LOOP