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 support@ccsinfo.com

Should be simple, convert 4 bytes to float32

 
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

Should be simple, convert 4 bytes to float32
PostPosted: Tue Nov 03, 2009 5:23 pm     Reply with quote

With the pcwhd 4.096 and PIC24F, my float32 should be IEEE format, 4 bytes, correct? I have the 4 hex bytes in an eeprom and I need to convert the bytes to float. What is the command for this? Thanks.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 5:29 pm     Reply with quote

It's no actual conversion, just a copy. You can use make32() built in function to combine the bytes. If I remember right, PCD is using IEEE float with reversed byte order.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed Nov 04, 2009 8:46 am     Reply with quote

Ok, I get it....

Code:


float readfile(int16 srval){
   float rtval;
   pathval[0] = read_ext_eeprom(srval);
   pathval[1] = read_ext_eeprom(srval + 1);
   pathval[2] = read_ext_eeprom(srval + 2);
   pathval[3] = read_ext_eeprom(srval + 3);
   pathv = make32(pathval[3],pathval[2],pathval[1],pathval[0]);
   memcpy(&rtval,&pathv,4);
   return rtval;
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Nov 04, 2009 9:34 am     Reply with quote

Yes, basically correct, but:
Code:
float readfile(int16 srval){
   union {
   float rtval;
   int8 pathval[4];
  }u;
   u.pathval[0] = read_ext_eeprom(srval);
   u.pathval[1] = read_ext_eeprom(srval + 1);
   u.pathval[2] = read_ext_eeprom(srval + 2);
   u.pathval[3] = read_ext_eeprom(srval + 3);
   // Two copy actions can be saved
   //pathv = make32(pathval[3],pathval[2],pathval[1],pathval[0]);
   //memcpy(&rtval,&pathv,4);
   return u.rtval;
}
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