Last Updated: February 25, 2016
·
659
· armahillo

easy Ruby base conversion

Fixnum.to_s accepts an integer parameter specifying what base you want it to represent in.

16.to_s(16)

=> "10"

255.to_s(16)

=> "ff"

You can get really crazy with this cheez-whiz though:

24.to_s(25)

=> "9k"

35.to_s(36)

=> "z"

but not too crazy...

36.to_s(37)

ArgumentError: invalid radix 37