QBASIC PROGRAM TO CALCULATE DECIMAL EQUIVALENT OF A HEXADECIMAL NUMBER

QBASIC PROGRAM TO CALCULATE DECIMAL EQUIVALENT OF A HEXADECIMAL NUMBER


C = 12 5A = 90 10B =267 DEF = 3567,etc.


CLS
 INPUT "ENTER HEXADECIMAL NUMBER"; N$
 FOR I = LEN(N$) TO 1 STEP -1
 B$ = MID$(N$, I, 1)
 IF B$ = "A" THEN B$ = "10"
 IF B$ = "B" THEN B$ = "11"
 IF B$ = "C" THEN B$ = "12"
 IF B$ = "D" THEN B$ = "13"
 IF B$ = "E" THEN B$ = "14"
 IF B$ = "F" THEN B$ = "15"
 
 S = S + VAL(B$) * 16 ^ P
 
 P = P + 1
 NEXT I
 PRINT "DECIMAL EQUIVALENT VALUE="; S
 END

USING SUB


DECLARE SUB HEXD(N$)
 CLS
 INPUT "ENTER HEXADECIMAL NUMBER"; N$
 CALL HEXD(N$)
 END
 
 SUB HEXD(N$)
 FOR I = LEN(N$) TO 1 STEP -1
 B$ = MID$(N$, I, 1)
 IF B$ = "A" THEN B$ = "10"
 IF B$ = "B" THEN B$ = "11"
 IF B$ = "C" THEN B$ = "12"
 IF B$ = "D" THEN B$ = "13"
 IF B$ = "E" THEN B$ = "14"
 IF B$ = "F" THEN B$ = "15"
 
 S = S + VAL(B$) * 16 ^ P
 
 P = P + 1
 NEXT I
 PRINT "DECIMAL EQUIVALENT VALUE="; S
 END SUB

Post a Comment

0 Comments