aspose file tools
The moose likes Beginning Java and the fly likes Outputing Binary Numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Outputing Binary Numbers" Watch "Outputing Binary Numbers" New topic
Author

Outputing Binary Numbers

Joe Hoppe
Greenhorn

Joined: Jan 28, 2004
Posts: 2
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Joe Hoppe
Greenhorn

Joined: Jan 28, 2004
Posts: 2
That's not a bad idea about converting from from the IEEE 754 Standard... I didn't think of that.
But I decided to do it manually. On the positive side (opposing my wasting time), it gives me a little greater control over the output.
Thanks
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Outputing Binary Numbers
 
Similar Threads
20102010
converting fractioanl value to Binary form
Ordinal Coparisons Question
Right Shift operator
MAX_VALUE