Is there a built in way to convert an integer in Ruby into its hexadecimal equivalent.
The opposite of
"0A".to_i(16)
=>10
or
"0A".hex
=>10
I know how to roll my own, but it's probably more efficient to use a built in ruby function
Is there a built in way to convert an integer in Ruby into its hexadecimal equivalent.
The opposite of
"0A".to_i(16)
=>10
or
"0A".hex
=>10
I know how to roll my own, but it's probably more efficient to use a built in ruby function
how about this:
10.to_s(16) #=> "a"
255.to_s(16) #=> "ff"
Documented here [edit - my bad I copy pasted my link too fast and put the String one instead of the Fixnum one]