Algorithms and Data Structures © N. Wirth 1985 (Oberon version: August 2004).
§ 1.3 Decimal representation of y = 2^(-n)
MODULE Power;
IMPORT Out;
PROCEDURE Do*(N: INTEGER);
VAR i, k, r: INTEGER;
d: ARRAY 300 OF INTEGER;
BEGIN
ASSERT((0 <= N) & (N <= LEN(d)));
FOR k := 0 TO N-1 DO
Out.Char("."); r := 0;
FOR i := 0 TO k-1 DO
r := 10*r + d[i]; d[i] := r DIV 2; r := r MOD 2;
Out.Char(CHR(d[i] + ORD("0")))
END;
d[k] := 5; Out.Char("5"); Out.Ln
END
END Do;
END Power.