Formatting binary values in Scala

前端 未结 8 976
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 19:15

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

8条回答
  •  爱一瞬间的悲伤
    2020-12-08 20:06

    Here is one more way (old Java):

    val x = 5
    val str = Integer.toString(x,2)
    

    Just like Lauri answer, it doesn't print leading zeros.

提交回复
热议问题