hex / rescue

M

mark greenlancer

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
 
F

Florian Gross

mark said:
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
 
M

Martin DeMello

mark greenlancer said:
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
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top