# Converting Integer to binary string

**URL:** <https://www.ruby-forum.com/t/converting-integer-to-binary-string/71732>\
**Category:** Ruby\
**Created:** [February 22, 2006, 7:05am UTC](https://www.ruby-forum.com/t/converting-integer-to-binary-string/71732 "2006-02-22T07:05:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harold\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Harold\_H](https://www.ruby-forum.com/u/Harold_H)\
**Post date:** [February 22, 2006, 7:05am UTC](https://www.ruby-forum.com/t/converting-integer-to-binary-string/71732/1 "2006-02-22T07:05:11Z")

</div>

Hello all,

I tried searching the list for this, but didn’t see the answer  
anywhere. A lot of people trying to do the opposite, but… 🙂

I’d like to convert the Integer 585 to the string “1001001001”

I see from the docs for Fixnum#[] that I could hack something together:

30.downto(0) { |i| print 585[i] }

But sometimes you just _know_ there’s a better way…

Thanks in advance,  
-Harold

---

<div class="post-metadata">

**Author:** ![Harold\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Harold\_H](https://www.ruby-forum.com/u/Harold_H)\
**Post date:** [February 22, 2006, 7:08am UTC](https://www.ruby-forum.com/t/converting-integer-to-binary-string/71732/2 "2006-02-22T07:08:14Z")

</div>

585.to\_s(2)

## – Kent

> **[DATANOISE.COM](https://www.datanoise.com/)**
>
> DATANOISE.COM - Contact us for any business inquiries

---

<div class="post-metadata">

**Author:** ![Harold\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Harold\_H](https://www.ruby-forum.com/u/Harold_H)\
**Post date:** [February 22, 2006, 7:26am UTC](https://www.ruby-forum.com/t/converting-integer-to-binary-string/71732/3 "2006-02-22T07:26:29Z")

</div>

Dah! Thank you.

Man, I was trying all kinds of crazy business.

585.to\_s.to\_i(2)

☹

Thanks again :P,  
-Harold
