# QBasic Programming

## WAP to convert hexadecimal number to decimal number

CLS
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 PROCEDURE
DECLARE SUB CONV(N\$)
CLS
CALL CONV(N\$)
END
SUB CONV(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

USING FUNCTION PROCEDURE
DECLARE FUNCTION CONV(N\$)
CLS
PRINT "DECIMAL EQUIVALENT VALUE="; CONV(N\$)
END
FUNCTION CONV(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
CONV = S
END FUNCTION