From: Alex Gutteridge Date: 2007-03-26T13:03:48+09:00 Subject: Re: how to tranlsate number to binary? On 26 Mar 2007, at 12:32, Ak 756 wrote: > Mike Moore wrote: > >> irb(main):008:0> int_to_binary(903) >> => "001110000111" > > Hi ,thanks for advise. > I want my function to give output 100100000011 for input 903. Where > '1001','0000','0011' is the binary value for 9,0,3 > Is there efficient way to do this? > > -- > Posted via http://www.ruby-forum.com/. > 903.to_s.split(//).map{|n| sprintf("%04d",n.to_i.to_s(2))}.join Alex Gutteridge Bioinformatics Center Kyoto University