[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Converting Integer to binary string

Harold Hausman

2/22/2006 6:01:00 AM

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


6 Answers

Kent Sibilev

2/22/2006 6:07:00 AM

0

585.to_s(2)

--
Kent
---
http://www.dat...



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


Harold Hausman

2/22/2006 6:24:00 AM

0

Dah! Thank you.

Man, I was trying all kinds of crazy business.

585.to_s.to_i(2)

:(

Thanks again :P,
-Harold

On 2/21/06, Kent Sibilev <ksruby@gmail.com> wrote:
> 585.to_s(2)
>
> --
> Kent
> ---
> http://www.dat...
>
>
>
> 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.. :)
> >
> > 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
> >
> >
>
>


Ophelia

5/7/2010 10:38:00 AM

0



"Maria" <down@heel.org.uk> wrote in message
news:T8Sdna_-abcFQH7WnZ2dnUVZ8s-dnZ2d@bt.com...
> On 06/05/2010 19:41, November 5 wrote:
>> Not really related to the question but does your brother have any
>> skills or interests he can use to be his own boss? Like a small shop
>> on Ebay?
>>
>> Do not presume that the ideal way through life is to get a salaried
>> job as an employee. Quite the opposite it is much more rewarding to
>> lead rather than follow.
>
> Unfortunately he is completely devoid of any initiative whatsoever.

Maria, you have plenty of initiative. If work could be found for him in the
way described above, could he not work for 'you' ie with you managing him?
--
--
https://www.shop.helpforhero...

Maria

5/7/2010 10:48:00 AM

0

On 07/05/2010 11:37, Ophelia wrote:
>
>
> "Maria" <down@heel.org.uk> wrote in message
> news:T8Sdna_-abcFQH7WnZ2dnUVZ8s-dnZ2d@bt.com...
>> On 06/05/2010 19:41, November 5 wrote:
>>> Not really related to the question but does your brother have any
>>> skills or interests he can use to be his own boss? Like a small shop
>>> on Ebay?
>>>
>>> Do not presume that the ideal way through life is to get a salaried
>>> job as an employee. Quite the opposite it is much more rewarding to
>>> lead rather than follow.
>>
>> Unfortunately he is completely devoid of any initiative whatsoever.
>
> Maria, you have plenty of initiative. If work could be found for him in the
> way described above, could he not work for 'you' ie with you managing him?

Unfortunately not - he is unmanageable.
55, never married, hardly ever a girlfriend, no children - can you
imagine? He never takes advice. I was listening to my 8 year old read to
me yesterday, and he just walked in and started talking at me. He could
hear the boy reading and see me listening, but just carried on getting
louder and louder until I paid him attention. In fact if he comes here
again today, he may well end up with the tv remote jammed somewhere the
sun don't shine...

Ophelia

5/7/2010 10:54:00 AM

0



"Maria" <down@heel.org.uk> wrote in message
news:8uWdnWfCOodGcn7WnZ2dnUVZ8udi4p2d@bt.com...
> On 07/05/2010 11:37, Ophelia wrote:
>>
>>
>> "Maria" <down@heel.org.uk> wrote in message
>> news:T8Sdna_-abcFQH7WnZ2dnUVZ8s-dnZ2d@bt.com...
>>> On 06/05/2010 19:41, November 5 wrote:
>>>> Not really related to the question but does your brother have any
>>>> skills or interests he can use to be his own boss? Like a small shop
>>>> on Ebay?
>>>>
>>>> Do not presume that the ideal way through life is to get a salaried
>>>> job as an employee. Quite the opposite it is much more rewarding to
>>>> lead rather than follow.
>>>
>>> Unfortunately he is completely devoid of any initiative whatsoever.
>>
>> Maria, you have plenty of initiative. If work could be found for him in
>> the
>> way described above, could he not work for 'you' ie with you managing
>> him?
>
> Unfortunately not - he is unmanageable.
> 55, never married, hardly ever a girlfriend, no children - can you
> imagine? He never takes advice. I was listening to my 8 year old read to
> me yesterday, and he just walked in and started talking at me. He could
> hear the boy reading and see me listening, but just carried on getting
> louder and louder until I paid him attention. In fact if he comes here
> again today, he may well end up with the tv remote jammed somewhere the
> sun don't shine...

Oh dear... although such a conclusion might make him sit up and take
notice... errr.. well, perhaps not the 'sit up' bit :)


--
--
https://www.shop.helpforhero...

Maria

5/7/2010 11:01:00 AM

0

On 07/05/2010 11:54, Ophelia wrote:
>
>
> "Maria" <down@heel.org.uk> wrote in message
> news:8uWdnWfCOodGcn7WnZ2dnUVZ8udi4p2d@bt.com...
>> On 07/05/2010 11:37, Ophelia wrote:
>>>
>>>
>>> "Maria" <down@heel.org.uk> wrote in message
>>> news:T8Sdna_-abcFQH7WnZ2dnUVZ8s-dnZ2d@bt.com...
>>>> On 06/05/2010 19:41, November 5 wrote:
>>>>> Not really related to the question but does your brother have any
>>>>> skills or interests he can use to be his own boss? Like a small shop
>>>>> on Ebay?
>>>>>
>>>>> Do not presume that the ideal way through life is to get a salaried
>>>>> job as an employee. Quite the opposite it is much more rewarding to
>>>>> lead rather than follow.
>>>>
>>>> Unfortunately he is completely devoid of any initiative whatsoever.
>>>
>>> Maria, you have plenty of initiative. If work could be found for him
>>> in the
>>> way described above, could he not work for 'you' ie with you managing
>>> him?
>>
>> Unfortunately not - he is unmanageable.
>> 55, never married, hardly ever a girlfriend, no children - can you
>> imagine? He never takes advice. I was listening to my 8 year old read
>> to me yesterday, and he just walked in and started talking at me. He
>> could hear the boy reading and see me listening, but just carried on
>> getting louder and louder until I paid him attention. In fact if he
>> comes here again today, he may well end up with the tv remote jammed
>> somewhere the sun don't shine...
>
> Oh dear... although such a conclusion might make him sit up and take
> notice... errr.. well, perhaps not the 'sit up' bit :)
>
>
:) Nothing would make him take notice. If I ran him over in my van, he'd
get up, walk off, and be back the next day!