I have a task to convert a 64-bit binary floating-point number into a base 10 decimal.
An example here:
Input:
64-bit binary floating-point number: 0100000000001001001000011111101101010100010001000010110100011000
Output:
Base 10 Decimal: 3.14
what I know here, first character is a sign = 0 (positive) , 1(negative).
Next 11 bits represent the exponent, and the rests are Mantissa.
My problem is I don’t know the math equation or the math solution to convert it. I am going to solve this task using Java.
>Solution :
Double.longBitsToDouble(long) takes a 64-bit long and converts it to a floating point double, which you can then print.
Given that, you can just use Long.parseLong(binary, 2) to convert a string of 0s and 1s to a long, and then use that method to get a floating point value.