From: "G.Durga Prasad" Date: 2007-03-26T21:17:25+09:00 Subject: Re: how to tranlsate number to binary? On 3/26/07, _why wrote: > On Mon, Mar 26, 2007 at 10:26:35AM +0900, Ak 756 wrote: > > For example, for input.txt as > > > > 903 > > 1047 > > > > I will get a new file as > > > > 100100000011 > > 0001000001000111 > > > > >> 0x903.to_s(2) > => "100100000011" > >> 0x1047.to_s(2) > => "1000001000111" > > And so it was: > > puts IO.read('input.txt').map { |x| x.to_i(16).to_s(2) }.join > > _why > > >> format("%0#{"193".length*4}b", 0x193) => "000110010011" to get leading zeros. And so , the following puts IO.read('input.txt').map { |x| format("%0#{x.chomp.length*4}b",x.to_i(16)) }.join("\n") Prasad