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

float to byte and byte to float

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

float to byte and byte to float
PostPosted: Fri Jul 09, 2004 12:09 pm     Reply with quote

I have float data
float Total;

and I used following method to change them into BYTE, here datanum is the address
Code:

    write_ext_eeprom(datanum, shift_right(&Total,24,0) & 0xFF);
     datanum=datanum+1;
     write_ext_eeprom(datanum, shift_right(&Total,16,0) & 0xFF);
     datanum=datanum+1;
     write_ext_eeprom(datanum, shift_right(&Total,8,0) & 0xFF);
     datanum=datanum+1;
     write_ext_eeprom(datanum, shift_right(&Total,0,0) & 0xFF);
     datanum=datanum+1;


to save them into a external memory
AM I right

Right now I need to read them from external memory to chip ram and transfer from BYTE to float

here
BYTE temp;
I need do something like these,put t\four byte reading into a float memory and display them, the following code is wrong, what is the correct one?
Code:


     temp=read_ext_eeprom(datanum);
     datanum=datanum+1;
     Total=shift_left(temp,24,0);
     temp=read_ext_eeprom(datanum);
     datanum=datanum+1;
     Total=Total |(temp<<16);
     read_ext_eeprom(datanum, temp);
     datanum=datanum+1;
     Total=Total |(temp<<8);
     temp=read_ext_eeprom(datanum);
     datanum=datanum+1;
     Total=Total |temp;


however, from byte to float error message[/quote]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 12:50 pm     Reply with quote

See the CCS FAQ topic which shows how to write and read a float
variable to EEPROM: http://www.ccsinfo.com/faq/?24


Here is the main CCS FAQ page:
http://www.ccsinfo.com/faq/
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