I need to convert a 32 bit floating point number to a 64 bit double precision number. I don't have to do any math on the number, just send it out the serial port in hex. I understand the structure:
Float:
31-sign
30-23 exponent with a bias of 127
22-0 Fraction
Double:
63-sign
62-52 exponent with a bias of 1023
51-0 Fraction
Does any one have a cheap trick to do this?
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
Posted: Tue Jun 22, 2004 8:45 am
Looks like you have the answer short of writing the code.
CCS exponent is 2^7 is zero with 64 bit float is 2^12 is zero so you need to shift to compensate.
the sign is the sign just in a different slot.
the mantissa is similar in both cases and represents
0.1bbbbbbbbb where b is 23 bits of zero or one so you have to move the CCS mantissa to its new location and fill the remaining positions in 64 bit float with zero.
Now not all float representations are alike. There is big endian and litttle endian as well as some hot dog tricks that Microsoft (tm) uses such as taking advantage of the fact that the most significant bit ( left most) is always 1 so they can stuff the sign in there and assume an implied 1 and thus increasing precision by one bit.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum