主题:[原创]二转十进制(绝对完整版)
CLS : flag = 1: INPUT a$
FOR i = 1 TO LEN(a$)
c$ = MID$(a$, i, 1)
IF c$ <> "1" AND c$ <> "0" AND c$ <> "-" AND c$ <> "." THEN PRINT "Reinput!": END
IF c$ = "." THEN nc = nc + 1: IF nc > 1 THEN PRINT "reinput": END
IF c$ = "-" AND i <> 1 THEN PRINT "reinput": END
NEXT i
'以上为判断输入格式
a = INSTR(a$, ".")
IF a <> 0 THEN
a1$ = MID$(a$, 1, a - 1): a2$ = MID$(a$, a + 1, LEN(a$) - a + 1)
ELSE
a1$ = a$: a2$ = "0"
END IF
'以上分割整数和小数部分
IF MID$(a1$, 1, 1) = "-" THEN a1$ = MID$(a1$, 2, LEN(a1$) - 1): PRINT a1$: flag = -1
b = 0: K = 0
FOR i = LEN(a1$) TO 1 STEP -1
b = b + VAL(MID$(a1$, i, 1)) * 2 ^ K: K = K + 1
NEXT i
K = 0
FOR i = 1 TO LEN(a2$)
K = K + 1: b = b + VAL(MID$(a2$, i, 1)) * 2 ^ (-K)
NEXT i
b = b * flag
'以上为求值部分
PRINT a$; "="; b
END
FOR i = 1 TO LEN(a$)
c$ = MID$(a$, i, 1)
IF c$ <> "1" AND c$ <> "0" AND c$ <> "-" AND c$ <> "." THEN PRINT "Reinput!": END
IF c$ = "." THEN nc = nc + 1: IF nc > 1 THEN PRINT "reinput": END
IF c$ = "-" AND i <> 1 THEN PRINT "reinput": END
NEXT i
'以上为判断输入格式
a = INSTR(a$, ".")
IF a <> 0 THEN
a1$ = MID$(a$, 1, a - 1): a2$ = MID$(a$, a + 1, LEN(a$) - a + 1)
ELSE
a1$ = a$: a2$ = "0"
END IF
'以上分割整数和小数部分
IF MID$(a1$, 1, 1) = "-" THEN a1$ = MID$(a1$, 2, LEN(a1$) - 1): PRINT a1$: flag = -1
b = 0: K = 0
FOR i = LEN(a1$) TO 1 STEP -1
b = b + VAL(MID$(a1$, i, 1)) * 2 ^ K: K = K + 1
NEXT i
K = 0
FOR i = 1 TO LEN(a2$)
K = K + 1: b = b + VAL(MID$(a2$, i, 1)) * 2 ^ (-K)
NEXT i
b = b * flag
'以上为求值部分
PRINT a$; "="; b
END