The following is the double value
-1.2316741412499997E8
The following is the method i am using :
Long.toBinaryString(Double.doubleToRawLongBits(-1.2316741412499997E8))
output: 1100000110011101010111011000101011011000011111111111111111111110
However when i tried doing it with value 2 i get the following output as shown below which is wrong.
Long.toBinaryString(Double.doubleToRawLongBits(2.0))
output: 100000000000000000000000000000000000000000000000000000000000000
Will someone tell me how do i convert a negative double value to binary.Thanks in advance.
I'm not sure what result you would like, but the result for 2.0 is absolutely correct.
Note that the number it gives is not zero padded, so it may seem to have the sign bit set, but the bit set is the highest bit of the exponent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With