# To\_s(base=2) in 1.8 only?

**URL:** <https://www.ruby-forum.com/t/to-s-base-2-in-1-8-only/157886>\
**Category:** Ruby\
**Created:** [January 16, 2009, 10:25am UTC](https://www.ruby-forum.com/t/to-s-base-2-in-1-8-only/157886 "2009-01-16T10:25:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tststs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tststs](https://www.ruby-forum.com/u/tststs)\
**Post date:** [January 16, 2009, 10:25am UTC](https://www.ruby-forum.com/t/to-s-base-2-in-1-8-only/157886/1 "2009-01-16T10:25:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tststs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tststs](https://www.ruby-forum.com/u/tststs)\
**Post date:** [January 16, 2009, 10:34am UTC](https://www.ruby-forum.com/t/to-s-base-2-in-1-8-only/157886/2 "2009-01-16T10:34:52Z")

</div>

On Fri, Jan 16, 2009 at 10:23 AM, ts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

I cannot test with 1.6.4 but probably the following works

“%b” % x

Pas d’quoi 😉  
R.

---

<div class="post-metadata">

**Author:** ![tststs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tststs](https://www.ruby-forum.com/u/tststs)\
**Post date:** [January 16, 2009, 4:10pm UTC](https://www.ruby-forum.com/t/to-s-base-2-in-1-8-only/157886/3 "2009-01-16T16:10:53Z")

</div>

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)

–Ken
