Search code examples
scalaintradix

Convert Scala Int to Ternary base


I want to convert Int to ternary base Like this:

42 -> 1120

What is the best way to do it in Scala?


Solution

  • You can use java.lang.Integer.toString(n, radix):

    Integer.toString(42, 3)