annotate 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
rev   line source
mike@0 1 var n, v, w, k: integer;
mike@0 2 var d: array 32 of boolean;
mike@0 3
mike@0 4 begin
mike@0 5 v := 31415926;
mike@0 6
mike@0 7 k := 0;
mike@0 8 while v <> 0 do
mike@0 9 d[k] := (v mod 2) <> 0;
mike@0 10 v := v div 2;
mike@0 11 k := k+1
mike@0 12 end;
mike@0 13
mike@0 14 w := 0;
mike@0 15 while k > 0 do
mike@0 16 k := k-1;
mike@0 17 w := 2*w;
mike@0 18 if d[k] then w := w+1 end
mike@0 19 end;
mike@0 20
mike@0 21 print w; newline
mike@0 22 end.
mike@0 23
mike@0 24 (*<<
mike@0 25 31415926
mike@0 26 >>*)