Forum: Ruby to_s(base=2) in 1.8 only?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E39115ce074a94cfebab628b5da83f7f?d=identicon&s=25 ts (Guest)
on 2009-01-16 10:25
(Received via mailing list)
f.each_byte {|x| print x.to_s(base=2).rjust(8,'0')

the above will fail in 1.6.4

wanna ask if to_s(base=2) is only available in 1.8?

my intention is to get each byte and output it as 10101010 format. Is
there any way that i can do that in 1.6.4?

thank you.
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-01-16 10:34
(Received via mailing list)
On Fri, Jan 16, 2009 at 10:23 AM, ts <> wrote:
I cannot test with 1.6.4 but probably the following works

"%b" % x

Pas d'quoi ;)
851acbab08553d1f7aa3eecad17f6aa9?d=identicon&s=25 Ken Bloom (Guest)
on 2009-01-16 16:10
(Received via mailing list)
On Fri, 16 Jan 2009 01:21:15 -0800, ts wrote:

> f.each_byte {|x| print x.to_s(base=2).rjust(8,'0')

Can't speak to the Ruby 1.6 issue, but the base= doesn't add anything to
your code (it just assigned 2 to a local variable). Just call x.to_s(2)

This topic is locked and can not be replied to.