binary<-function(p,l){ x=seq(1:l) r=p h=1/2 for (i in 1:l){ x[i]=(r>=h) r=r-x[i]*h h=h/2} x }