Qbasic program to convert binary number into decimal equivalent value
CLS
INPUT "ENTER BINARY NUMBER"; N$
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$(N$, I, 1)
S = S + VAL(B$) * 2 ^ P
P = P + 1
NEXT I
PRINT "DECIMAL EQUIVALENT VALUE="; S
END
USING SUB
DECLARE SUB BDEC(N$)
CLS
INPUT "ENTER BINARY NUMBER"; N$
CALL BDEC(N$)
END
SUB BDEC(N$)
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$(N$, I, 1)
S = S + VAL(B$) * 2 ^ P
P = P + 1
NEXT I
PRINT "DECIMAL EQUIVALENT VALUE="; S
END SUB
0 Comments