QBasic Programming

WAP to convert hexadecimal number to decimal number

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 PROCEDURE
DECLARE SUB CONV(N$)
CLS
INPUT "ENTER HEXADECIMAL NUMBER"; N$
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
INPUT "ENTER HEXADECIMAL NUMBER"; N$
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

WAP to convert decimal number to hexadecimal number (Prev Lesson)
(Next Lesson) WAP to input number of passengers and their destination
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!