From: Harold Hausman Date: 2007-03-26T10:38:15+09:00 Subject: Re: how to tranlsate number to binary? On 3/26/07, Ak 756 wrote: > Hi, I am a ruby newbie. I want to write a program which will scan a > input file, change every digital number into 4 bits len's binary > number. > For example, for input.txt as > > 903 > 1047 > > I will get a new file as > > 100100000011 > 0001000001000111 > > Would anyboby kindly help to tell me how to do this? I don't know what a "4 bits len's binary number" is. But here's how you convert decimal to binary in Ruby: irb(main):004:0> 903.to_s(2) => "1110000111" irb(main):005:0> 1+2+4+128+256+512 => 903 Hope that helps, -Harold