From: Ak 756 Date: 2007-03-26T14:00:24+09:00 Subject: Re: how to tranlsate number to binary? Gavin Kistner wrote: > On Mar 25, 10:06 pm, Joel VanderWerf wrote: >> Ak 756 wrote: >> > 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? >> >> "903".split("").map{|s| "%04b" % s.to_i}.join >> => "100100000011" > > No need to call to_i on the digit strings: > > irb(main):002:0> 903.to_s.split('').map{|n| "%04b" % n }.to_s > => "100100000011" Woo.., that's really what's I want. Thanks you guys-:) -- Posted via http://www.ruby-forum.com/.