4

Basically I have a Double defined in Scala and I'd like it in a binary representation. For example:

val myDouble: Double = 0
val myDoubleAs64BitString = "00000000"+
                            "00000000"+
                            "00000000"+
                            "00000000"+
                            "00000000"+
                            "00000000"+
                            "00000000"+
                            "00000000"

This may sound and look crazy but basically for what I'm doing it's not. I'm basically writing a Chess application and I need a decent way of getting feedback while testing bitboard representations.

James Murphy
  • 800
  • 1
  • 15
  • 29
  • For everyone that read this, http://scala-exercises.47deg.com/index.html – Enrique Quero Mar 03 '15 at 21:09
  • 1
    For a pure Java solution, you can check [this answer](http://stackoverflow.com/questions/6359847/convert-double-to-binary-representation). Also, it's worth noting that `myDouble` is an `Int` in this example. – resueman Mar 03 '15 at 21:16
  • Thanks @resueman corrected. I'm a Java developer transitioning to Scala so unfamiliar with all the syntax just yet. – James Murphy Mar 03 '15 at 21:27

1 Answers1

8

The syntax in Scala is the same for this problem.

java.lang.Long.toBinaryString(java.lang.Double.doubleToRawLongBits(myDouble))
Jonathan Crosmer
  • 786
  • 5
  • 19