Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting binary values in Scala

Does Scala have a built in formatter for binary data?

For example to print out: 00000011 for the Int value 3.

Writing one won't be difficult - just curious if it exists.

like image 334
Jack Avatar asked Feb 25 '12 08:02

Jack


1 Answers

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.

like image 159
Lauri Avatar answered Oct 07 '22 19:10

Lauri