Hi and thanks for helping,
(Working with Java) I've looked around a bit for converting a Double to base 2 (still in double) but I could not find a simple way. I read that given how Doubles were coded the methods like Double.doubleToRawLongBits() can give Base 2 but with a different interpretation.
For converting int it pretty simple with the method: Integer.toString(x, 2)
I was wondering if someone knew a simple way to convert a Double to it's base 2 correspondant as a Double? If I have a Double = 0.25 after the conversion I would like to see a double = 0.01.
Thanks
You can extract the part of a
double
like this.After that you can print the mantissa with
Long.toString(mantissa, 2)
and the exponent and sign however you like. This assumes normal numbers.