hex / rescue

Discussion in 'Ruby' started by mark greenlancer, Jul 15, 2004.

  1. 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
     
    mark greenlancer, Jul 15, 2004
    #1
    1. Advertising

  2. 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
     
    Florian Gross, Jul 15, 2004
    #2
    1. Advertising

  3. mark greenlancer <> 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
     
    Martin DeMello, Jul 15, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,223
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    474
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    590
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    18,881
  5. tim
    Replies:
    2
    Views:
    1,566
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page