Dec 222017
 
This file contains the source code in QuickBasic (4.5) to convert any base number in the range of base 2 to base 16 to decimal.
File HEXTODEC.ZIP from The Programmer’s Corner in
Category BASIC Language
This file contains the source code in QuickBasic (4.5) to convert any base number in the range of base 2 to base 16 to decimal.
File Name File Size Zip Size Zip Type
HEXTODEC.TXT 1402 477 deflated
TPCREAD.ME 199 165 deflated

Download File HEXTODEC.ZIP Here

Contents of the HEXTODEC.TXT file


REM Simple program to take any base number from base 2 to base 16 and
REM convert it to decimal

mbase = 1

DO WHILE mbase < 2 OR mbase > 16
PRINT "Enter base of number you wish to convert"
INPUT mbase
LOOP

LET flag = 1
DO WHILE flag = 1
LET ok = 1
PRINT "Enter base"; mbase; " number"
INPUT a$
LET length = LEN(a$)
LET numchar = length
LET power = numchar - 1
DO WHILE numchar > 0
LET current$ = LEFT$(RIGHT$(a$, numchar), 1)
LET value = ASC(current$)
IF value >= 65 AND value <= 70 THEN
decimal = mbase ^ (power) * (value - 45)
ELSEIF value >= 97 AND value <= 102 THEN
decimal = mbase ^ (power) * (value - 87)
ELSEIF value >= 48 AND value <= 57 THEN
decimal = mbase ^ (power) * (value - 48)
ELSEIF value = 46 THEN
total = total / (mbase ^ (length - (length - numchar)))
power = 0
decimal = 0
ELSE
PRINT "Invalid hexadecimal number"
LET ok = 0
LET numchar = 0
END IF
LET total = total + decimal
LET numchar = numchar - 1
LET power = power - 1
LOOP
IF ok = 1 THEN LET flag = 0
LOOP
PRINT a$
PRINT total



 December 22, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)