We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have got a problem with my funtion to convert an array to float. I use the "Debug" to see the value of my variables. The problem is in the multiplication on the second element of array fd[1] only when there is a "7","8" or "9", for example to convert "070000" the value of bux=4464, for others value the funtion works perfectly.
float Conv_C2F_FE(unsigned char fd[6]) {float bux; bux=(fd[0]-0x30)*100000; bux=bux+(fd[1]-0x30)*10000; bux=bux+(fd[2]-0x30)*1000; bux=bux+(fd[3]-0x30)*100; bux=bux+(fd[4]-0x30)*10; bux=bux+(fd[5]-0x30); return bux; }
Thanks you are a genius! we have been 3 person asking for why didn't work, now seems so easy. thank you very much. Ruben.
Why don't you just use sscanf()?
You know, there is a library function (strtod) that does exactly what you want. http://www.keil.com/support/man/docs/c51/c51_strtod.htm Jon
"You know, there is a library function (strtod) that does exactly what you want." Well, maybe not exactly. Being a 'C' string function, it requires a null terminator. This may or may not match the requirement...