Is there a built in way to convert an integer in Ruby into its hexadecimal equivalent?
Something like the opposite of String#to_i:
'0A'.to_i(16) #=>10
Like perhaps:
'0A'.hex #=>10
I know how to roll my own, but it’s probably more efficient to use a built in Ruby function.
You can give
to_sa base other than 10:Note that in ruby 2.4
FixNumandBigNumwere unified in theIntegerclass. If you are using an older ruby check the documentation of FixNum#to_sand BigNum#to_s