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

Dividing a 32bit floating number into (4) 8-bit integers for

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







Dividing a 32bit floating number into (4) 8-bit integers for
PostPosted: Tue May 13, 2003 5:46 am     Reply with quote

I have a few 32bit floating numbers which I want to use to send to an EEPROM for storage. Does anyone have an idea of how to break this 32bit floating number into 4 separate 8-bit integers???

The make8() function only works on integers and does work with floating point numbers.

Thanks

liche
___________________________
This message was ported from CCS's old forum
Original Post ID: 14400
Tomi
Guest







Re: Dividing a 32bit floating number into (4) 8-bit integers
PostPosted: Tue May 13, 2003 6:37 am     Reply with quote

See CCS FAQ "How do I write variables to EEPROM that are not a byte?" That example is about saving floats.

:=I have a few 32bit floating numbers which I want to use to send to an EEPROM for storage. Does anyone have an idea of how to break this 32bit floating number into 4 separate 8-bit integers???
:=
:=The make8() function only works on integers and does work with floating point numbers.
:=
:=Thanks
:=
:=liche
___________________________
This message was ported from CCS's old forum
Original Post ID: 14403
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: Dividing a 32bit floating number into (4) 8-bit integers
PostPosted: Tue May 13, 2003 6:39 am     Reply with quote

Here's the answer to your question:
<a href="http://www.ccsinfo.com/faq/?24" TARGET="_blank">http://www.ccsinfo.com/faq/?24</a>

Personally, I prefer the unions:

union Convert
{
float f;
int8 i[4];
};

union Convert C;
C.f=some_float_value;
write_eeprom(address,i[0] ) ;
write_eeprom(address+1,i[1] ) ;
write_eeprom(address+2,i[2] ) ;
write_eeprom(address+3,i[3] ) ;


I hope that answers your question.

__Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 14404
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