Convert a number to binary

most-significant digit first,

without using reverse

conv(42) ==> [1,0,1,0,1,0]

 

conv(0) Þ [0];

conv(N) Þ conv(N,[]);

conv(0,A) Þ A;

conv(N,A) Þ conv(N/2,[N%2|A]);

e.g.

conv(1) ==> [1]

conv(13) Þ conv(13,[])

         Þ conv(6,[1])

         Þ conv(3,[0,1])

         Þ conv(1,[1,0,1])

         Þ conv(0,[1,1,0,1])

         Þ [1,1,0,1];

 

To Next Slide To Previous Slide To Contents