On 29 Mar 2006 06:16:36 -0800,
wrote, quoted or
indirectly quoted someone who said :
>String toConvert = "bfdf000000000000";
>Double dblDouble = Double.longBitsToDouble(Long.parseLong(toConvert,
>16));
>System.out.print(dblDouble);
The problem is parseLong is expecting a signed number. The unsigned
one you give it is too big.
You can see the problem if you run this code fragment
String toConvert = "bfdf000000000000";
long temp = Long.parseLong( toConvert, 16 );
System.out.println( temp );
Your code contains another error, masked by boxing. This is closer to
what you meant:
long temp = 0xbfdf000000000000L;
double d = Double.longBitsToDouble( temp );
System.out.println( d );
Double.longBitsToDouble returns a double, not a Double.
I see three ways to solve your unsigned problem:
1. arrange to get get the bits in binary rather than hex.
2. construct the low and high 32 bits then shift then OR.
3. Convert hex chars from unsigned to signed, perhaps when generated
(see
http://mindprod.com/jgloss/hex.html) or by checking for high
char being >= 8 , replace it with equivalent char <8 with high bit
off, then mask the sign bit back in afterwards. Conceptually simple,
but in practice long winded.
For hints on how to do the details, so the at the code in
http://mindprod.com/products1.html#LEDATASTREAM
for readDouble
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.