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.
dear friends
i would like to know how can we convert the ascii values to decimal values to perform some calculations. my requirement is that i am receiving a six digit ascii data via com port of AT 89c52.now i have to perform some calculations with this value and send back via comport.so first i have tonvert the receiving ASCII value to a float value, then after the necessary calculations i've to convert the result again to ASCII to send via com port.can anyone provide some idea ?
sunish
Convert ascii text to binary integers... hm, ascii to integer... a to i.... how might I do that?
You might also look under string-to-long (strtol or strtoul) and the giant sledgehammer for converting string input, scanf.
hai thank you for the reply i will explain the requirement i am receiving six charectors via USART from the computer.we know that will be in ascii format.i stored the charectors in an array.i want to devide the value with a number which will be read from the key board.then i want to send back the result to the computer.to do this first i've to convert the ascii values to a float value because after division the result can be a float value.now to send back the result,we should again convert the value to the ascii format.in keil,there are functions called toascii and to int but i cannot apply this for any float value.is there any way that i can solve this problem?
thank you
sunish nair
Go to the C51 Library Reference and read it!
You already have the link.
There are functions there that do what you require!
dear Andy
i'd checked the entire keil library,and i found there's a function to convert ascii value to float.but i could not find a function which converts float to ascii.could you please provide some tips or sample code
thanking you
sprintf?
thank you all for the support when ever we have to display a float value on the lcd we have to convert the value to ASCII format.to display the same on the seven segment display,we have to extract every digits from the float value.how is it possible?
Convert it to ASCII and then look at each invididual character (string[5] -> string[0], string[1], etc.) ?
-- Joost
dear joost
thank you for the reply i am confucsed there.i could not find a solution to convert the float value to ascii.can you please help me in this?
One more time: sprintf
http://www.keil.com/support/man/docs/c51/c51_modf.htm
"we have to extract every digits from the float value.how is it possible?"
This is only possible, if you mean binary digits.
Every real number can not be exactly stored as a floating point number. Because of this, a floating point value does not always convert exactly to the decimal number you expect.
The extracted number may for example look like 2.99999999997.
Because of this, you normally do not want to make an exact extract, but want to round the number to a reasonable number of digits. This is what happens when using sprintf() with the %g conversion - it tries to establish the real number of value digits in the floating point number.