to_s(base=2) in 1.8 only?

T

ts

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.
 
R

Robert Dober

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.
I cannot test with 1.6.4 but probably the following works

"%b" % x

Pas d'quoi ;)
R.
 
K

Ken Bloom

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)

--Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top