posted 14 years ago
I am trying to output binary numbers to the standard stream. The problem is that I want to display them in the mathematically correct format.
Using 7.5 as a decimal example, to display it as:
111.1
Do I have to write my own method to convert these, or is there a simpler way?
Thanks,
Joe Hoppe
Using 7.5 as a decimal example, to display it as:
111.1
Do I have to write my own method to convert these, or is there a simpler way?
Thanks,
Joe Hoppe
posted 14 years ago
Welcome to JavaRanch, Joe!
If you're not already familiar with it, you'll definitely want to get to know the J2SE API Specification.
Notice that the Double class has a method or two that you might find useful  doubleToLongBits and doubleToRawLongBits. If you want to see the bits that either of these outputs, try a simple example such as the following.
If you understand the IEEE 754 floating point bit pattern, then you should be able to figure something out.
Otherwise, it wouldn't really be all that much much to write a simple algorithm to convert the number "by hand".
Let us know how you make out.
Good luck.
If you're not already familiar with it, you'll definitely want to get to know the J2SE API Specification.
Notice that the Double class has a method or two that you might find useful  doubleToLongBits and doubleToRawLongBits. If you want to see the bits that either of these outputs, try a simple example such as the following.
If you understand the IEEE 754 floating point bit pattern, then you should be able to figure something out.
Otherwise, it wouldn't really be all that much much to write a simple algorithm to convert the number "by hand".
Let us know how you make out.
Good luck.
Yup, yup, yup. Tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
