In Java we have Integer.toBinaryString(int) which returns binary string representing the integer.How to represent for numbers larger than Integer.MAX_VALUE? For example,double d = Math.pow(10,50),how to obtain binary string for d ?

Note that the java.lang.Double class has the doubleToLongBits method that returns a long value and that the Long class has the toBinaryString method. You really should have a copy of the JavaDocs unpacked on your hard drive and get familiar with using it - it saves lots of time. Bill

Arjunkumar Shastry
Ranch Hand

Joined: Feb 28, 2005
Posts: 986

posted

0

I think it won't handle the big number Math.pow(10,100).The only option is now to use,java.math.BigInteger.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825

5

posted

0

The doubleToLongBits method will handle any double - the reason being that it simply takes the 8 bytes of a double and returns them as 8 bytes of a long. Thus the bits represent the entire IEEE 754 floating point double - sign, exponent and mantissa. Bill