Converting Integer to binary string

H

Harold Hausman

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 }

But sometimes you just *know* there's a better way...

Thanks in advance,
-Harold
 
H

Harold Hausman

Dah! Thank you.

Man, I was trying all kinds of crazy business.

585.to_s.to_i(2)

:(

Thanks again :p,
-Harold

585.to_s(2)

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



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 }

But sometimes you just *know* there's a better way...

Thanks in advance,
-Harold

 

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
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top