主题:带小数十进制转二进制
CLS
INPUT a
a$ = LTRIM$(STR$(a))
p = INSTR(1, a$, ".")
IF p > 0 THEN a = VAL(LEFT$(a$, p - 1))
PRINT "("; a$; ")"; "10=(";
DIM z(10000)
DO
k = k + 1
z(k) = a MOD 2
a = a \ 2
LOOP UNTIL a = 0
FOR i = k TO 1 STEP -1
PRINT USING "#"; z(i);
NEXT i
IF p = 0 THEN PRINT ")2": END
DIM x(10000)
a = VAL("0" + MID$(a$, p, LEN(a$) - p + 1))
k = 0: PRINT ".";
DO
a = a * 2
k = k + 1
x(k) = VAL(LEFT$(LTRIM$(STR$(a)), 1))
IF a = 0 OR a = 1 THEN EXIT DO
IF a >= 1 THEN a = a - 1
LOOP
FOR i = 1 TO k
PRINT LTRIM$(STR$(x(i)));
NEXT i
PRINT ")2"
END
INPUT a
a$ = LTRIM$(STR$(a))
p = INSTR(1, a$, ".")
IF p > 0 THEN a = VAL(LEFT$(a$, p - 1))
PRINT "("; a$; ")"; "10=(";
DIM z(10000)
DO
k = k + 1
z(k) = a MOD 2
a = a \ 2
LOOP UNTIL a = 0
FOR i = k TO 1 STEP -1
PRINT USING "#"; z(i);
NEXT i
IF p = 0 THEN PRINT ")2": END
DIM x(10000)
a = VAL("0" + MID$(a$, p, LEN(a$) - p + 1))
k = 0: PRINT ".";
DO
a = a * 2
k = k + 1
x(k) = VAL(LEFT$(LTRIM$(STR$(a)), 1))
IF a = 0 OR a = 1 THEN EXIT DO
IF a >= 1 THEN a = a - 1
LOOP
FOR i = 1 TO k
PRINT LTRIM$(STR$(x(i)));
NEXT i
PRINT ")2"
END