comparison lab2/binary.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 var n, v, w, k: integer;
2 var d: array 32 of boolean;
3
4 begin
5 v := 31415926;
6
7 k := 0;
8 while v <> 0 do
9 d[k] := (v mod 2) <> 0;
10 v := v div 2;
11 k := k+1
12 end;
13
14 w := 0;
15 while k > 0 do
16 k := k-1;
17 w := 2*w;
18 if d[k] then w := w+1 end
19 end;
20
21 print w; newline
22 end.
23
24 (*<<
25 31415926
26 >>*)