Convert a Long to base 36 in scala

base36, long-integer, scala

Solution

The class java.lang.Long has a static method toString(long i, int radix) which will convert a Long into a string representation of another base. "Radix" means the same thing as "base" in this context.

val myLong = 25000L
val longInBase36:String = java.lang.Long.toString(myLong, 36)

Scala will treat your scala Long value as a java.lang.Long when necessary, so you can always look for methods in the Java API documentation when necessary. See: http://docs.oracle.com/javase/6/docs/api/java/lang/Long.html

Problem

How can I convert a Long to base36 ? Along with your answer can explain how you came to the answer? I've checked the scaladocs for Long for converting to a different base, and on converting a Long to a BigInt. I saw that BigInt does have `toString( base )` so a solution could involve changing the type, but I couldn't figure out how. Note: I'm new to scala / java / type-safe languages so I could be overlooking something trivial.

Original source