12-18-2004, 11:07 PM
My binary to decimal converter won't work. I've tried multiple ways and multiple methods and it's always flawed.
Can anyone help? It messes up when I get to number 101. Thanks!
Code:
CLS
INPUT "Enter binary binary number", binary1$
length = LEN(binary1$)
t = length + 1
g = -1
DO
t = t - 1
z = z + 1
g = g + 1
IF length = 1 THEN t = 1
b$ = MID$(binary1$, t, t)
IF b$ = "1" THEN b1 = 1: result = b1 * (2 ^ g)
decimal1 = decimal1 + result
IF z = length THEN EXIT DO
LOOP
PRINT decimal1
Can anyone help? It messes up when I get to number 101. Thanks!