| 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
|
 |
 |
|
|
subject: Outputing Binary Numbers
|
|
|