[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

String#pack?

ggarramuno

10/1/2004 10:05:00 PM

I was wondering if there was a method in ruby to obtain the hexadecimal
representation of numbers (ie. fixnum, floats, mainly) in either msb or in lsb
order.
Basically, I'm kind of looking for the opposite function of String#unpack().

3 Answers

James Gray

10/1/2004 11:09:00 PM

0

On Oct 1, 2004, at 5:14 PM, GGarramuno wrote:

> I was wondering if there was a method in ruby to obtain the hexadecimal
> representation of numbers (ie. fixnum, floats, mainly) in either msb
> or in lsb
> order.
> Basically, I'm kind of looking for the opposite function of
> String#unpack().

I'm not 100% sure I understood the question, but does this do what
you're after?

% ruby -e 'puts "%x" % 123'
7b

Hope that helps.

James Edward Gray II



Florian Gross

10/1/2004 11:38:00 PM

0

GGarramuno wrote:

> Basically, I'm kind of looking for the opposite function of String#unpack().

It's Array#pack.

Regards,
Florian Gross

Robert Klemme

10/2/2004 10:42:00 AM

0


"Florian Gross" <flgr@ccan.de> schrieb im Newsbeitrag
news:2s682mF1haft1U1@uni-berlin.de...
> GGarramuno wrote:
>
>> Basically, I'm kind of looking for the opposite function of
>> String#unpack().
>
> It's Array#pack.

Also there is to_s(radix):

>> 128.to_s(16)
=> "80"

Kind regards

robert