Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert 64-Bit Binary floating-point number into a base 10 decimal

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading