diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lab2/binary.p	Thu Oct 05 08:04:15 2017 +0100
@@ -0,0 +1,26 @@
+var n, v, w, k: integer; 
+var d: array 32 of boolean;
+
+begin
+  v := 31415926;
+
+  k := 0;
+  while v <> 0 do
+    d[k] := (v mod 2) <> 0;
+    v := v div 2;
+    k := k+1
+  end;
+
+  w := 0;
+  while k > 0 do
+    k := k-1;
+    w := 2*w;
+    if d[k] then w := w+1 end
+  end;
+
+  print w; newline
+end.
+
+(*<<
+ 31415926
+>>*)