CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Float to Double

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

Float to Double
PostPosted: Mon Jun 21, 2004 12:59 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Tue Jun 22, 2004 8:45 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group