Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > hex / rescue

Reply
Thread Tools

hex / rescue

 
 
mark greenlancer
Guest
Posts: n/a
 
      07-15-2004
hello,

there are a few questions after I've read the
manual...

``String.hex´´ converts a hex-string to a decimal
number. But how to convert a decimal number to a
hex value?

If I do

begin
...
rescue
...
end

catches the rescue part every error?
I can also write ``rescue StandardError, SyntaxError, ...


greetings,
mark
 
Reply With Quote
 
 
 
 
Florian Gross
Guest
Posts: n/a
 
      07-15-2004
mark greenlancer wrote:

> hello,


Moin!

>
> there are a few questions after I've read the
> manual...
>
> ``String.hex´´ converts a hex-string to a decimal
> number. But how to convert a decimal number to a
> hex value?


I think that String#hex should not be used anymore.

I would use "deadbeef".to_i(16) for converting from a String to a number
and 36.to_s(16) for the other way.

> If I do
>
> begin
> ...
> rescue
> ...
> end
>
> catches the rescue part every error?
> I can also write ``rescue StandardError, SyntaxError, ...


It is the same as 'rescue StandardError' -- if you want to rescue all
errors you should use 'rescue Exception' instead.

> greetings,
> mark


Regards,
Florian Gross
 
Reply With Quote
 
 
 
 
Martin DeMello
Guest
Posts: n/a
 
      07-15-2004
mark greenlancer <(E-Mail Removed)> wrote:
> hello,
>
> there are a few questions after I've read the
> manual...
>
> ``String.hex´´ converts a hex-string to a decimal
> number. But how to convert a decimal number to a
> hex value?


number.to_s(16)

It works for other bases too

martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex string to hex value tim Python 8 11-23-2005 06:27 PM
[Fwd: Re: hex string to hex value] tim Python 2 11-23-2005 07:18 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex value in string back to real hex value jack Python 4 09-08-2004 07:11 AM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments