Converting Integer to binary string

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.. :slight_smile:

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

585.to_s(2)

路路路

--
Kent
---

On 2/22/06, Harold Hausman <hhausman@gmail.com> wrote:

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.. :slight_smile:

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

Dah! Thank you.

Man, I was trying all kinds of crazy business.

585.to_s.to_i(2)

:frowning:

Thanks again :P,
-Harold

路路路

On 2/21/06, Kent Sibilev <ksruby@gmail.com> wrote:

585.to_s(2)

--
Kent
---
http://www.datanoise.com

On 2/22/06, Harold Hausman <hhausman@gmail.com> wrote:
> 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.. :slight_smile:
>
> 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
>
>