How to I display the binary equivalent of a number? I tried this: b = 0b1101 puts b # returns decimal value ( 13 ) b.to_bn # generates "unable to convert FIXNUM to STRING.." error. -- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/2b4be5a7/attachment.html
> How to I display the binary equivalent of a number? I tried this: > > b = 0b1101 > puts b # returns decimal value ( 13 ) > > b.to_bn # generates "unable to convert FIXNUM to STRING.." error.b.to_s(2) Regards, Rimantas -- http://rimantas.com/
Larry Kelly wrote:> How to I display the binary equivalent of a number? I tried this: > > b = 0b1101 > puts b # returns decimal value ( 13 ) > > b.to_bn # generates "unable to convert FIXNUM to STRING.." error.<number>.to_s(base) So, in this case 13.to_s(2) => "1101" -- Posted via http://www.ruby-forum.com/.
How elegant!, Wonderful! Thanks, -Larry On 7/20/06, Fred Wulff <fwulff@mobileevolution.com> wrote:> > Larry Kelly wrote: > > How to I display the binary equivalent of a number? I tried this: > > > > b = 0b1101 > > puts b # returns decimal value ( 13 ) > > > > b.to_bn # generates "unable to convert FIXNUM to STRING.." error. > > <number>.to_s(base) > > So, in this case > > 13.to_s(2) > => "1101" > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/aa7c6cb1/attachment.html