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 or char array

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



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

float to byte or char array
PostPosted: Wed May 27, 2009 8:18 am     Reply with quote

How can I convert float to byte or char array

For example
if x=(float)123456789345.545
then,
function find the following result for me...Where z is rhe array

z[0]=1;
z[1]=2;
z[2]=3;
z[3]=4;
z[4]=5;
z[5]=6;
z[6]=7;
z[7]=8;
z[8]=9;
z[9]=3;
z[10]=4;
z[11]=5;
z[12]='.';
z[13]=5;
z[14]=4;
z[15]=5;
Ttelmah
Guest







PostPosted: Wed May 27, 2009 8:41 am     Reply with quote

1) Sprintf.Just the same as printing a value out to the serial etc., except you send the result to a character array.
2) However, you won't get what you expect. Remember a CCS float, is only a 23bit + 1 value. Equivalent to about 6.5 digits of 'useable' precision...

Best Wishes
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PostPosted: Thu May 28, 2009 2:49 am     Reply with quote

I want to learn the following:

float x;

x=256*256*256*256*256;

I using calculator it's calculate it 1099511627776
in ccs it 's calculated as 1099511697920 why this is different?
Ttelmah
Guest







PostPosted: Thu May 28, 2009 3:27 am     Reply with quote

Look at what I have already posted. Only about 6.5 digits of 'real' precision. Count the number of digits that agree. The rest of the number is effectively 'garbage'.
If you have the PConvert tool (comes with the windows compilers), you can play with the numbers to see what is really stored.
Hex 53800000 gives 1.0995116E12. Change the Hex by just 1 to 53800001, and the decimal jumps to 1.095118E12. There is no possibility of storing a number between these values at all...
Do a web seqarch on numeric precision, and you will find a lot about this.

Best Wishes
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