Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Scala Double into a binary 64-bit String

Tags:

scala

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.

like image 777
James Murphy Avatar asked Feb 10 '23 18:02

James Murphy


1 Answers

The syntax in Scala is the same for this problem.

java.lang.Long.toBinaryString(java.lang.Double.doubleToRawLongBits(myDouble))
like image 174
Jonathan Crosmer Avatar answered Feb 16 '23 04:02

Jonathan Crosmer