Hi
How do you convert 7bit binary to decimal in QBASIC?
Thanks in advance.
Code: Select all
SUB Bin2Dec
COLOR 14: LOCATE 2, 30: PRINT "Binary to Decimal"
COLOR 10: LOCATE 5, 20: PRINT "Enter a binary number (1's or 0's):"
DO: Bin$ = INKEY$ 'string number entry 1 or 0 with backspace
IF Bin$ = "1" OR Bin$ = "0" THEN Binary$ = Binary$ + Bin$
L = LEN(Binary$)
IF L > 0 AND Bin$ = CHR$(8) THEN Binary$ = MID$(Binary$, 1, L - 1)
COLOR 14: LOCATE 5, 57: PRINT Binary$; " "
LOOP UNTIL L > 0 AND Bin$ = CHR$(13) 'enter quits
FOR i = 0 TO L - 1
place = VAL(MID$(Binary$, L - i, 1))
dec = place * 2 ^ i
Decimal = Decimal + dec
NEXT
COLOR 11: LOCATE 10, 30: PRINT "Decimal number ="; Decimal
END SUB
Return to “QBASIC and QB64 Questions & Answers”
Users browsing this forum: Bing [Bot] and 3 guests