Formatting binary values in Scala
I don't know of a direct API method to do it, but here is one way of doing it:
def toBinary(i: Int, digits: Int = 8) =
String.format("%" + digits + "s", i.toBinaryString).replace(' ', '0')
scala> 3.toBinaryString
res0: String = 11
Scala has an implicit conversion from Int to RichInt which has a method toBinaryString. This function does not print the leading zeroes though.