DSPRelated.com
Forums

how toconvert floating point numbers to ASCII format

Started by waji...@hotmail.com January 16, 2007
Hi i am new to dsp processing .I am using c6713.
I want to output the floating point numbers to a modem.
First i should convert these numbers to ASCII format.
Any related document or sample code whould be helpful for me.
Any response would be appreciated.
Thanks
wajahat
Wajahat-

> Hi i am new to dsp processing .I am using c6713.
> I want to output the floating point numbers to a modem.
> First i should convert these numbers to ASCII format.
> Any related document or sample code whould be helpful for me.
> Any response would be appreciated.

Do you mean send the float values via RS-232 from your DSK board to a modem? If not,
how is the modem connected and to what?

-Jeff
Jeff Brower wrote:
>
> Wajahat-
>
> > Hi i am new to dsp processing .I am using c6713.
> > I want to output the floating point numbers to a modem.
> > First i should convert these numbers to ASCII format.
> > Any related document or sample code whould be helpful for me.
> > Any response would be appreciated.
>
> Do you mean send the float values via RS-232 from your DSK board to a
> modem? If not,
> how is the modem connected and to what?
>
I would guess that the easiest way to convert numbers to ascii format is
to use the sprintf() command. There are several easy formats to use.
Traditionally it has some library size overhead which can be a bigger
issue on a constrained system than a general purpose system, but I find
it worth the trade off. It also does not check the length of the buffer
it is writing to, which means that you need to make sure you don't
buffer overflow.
char OutputString[80];
float Number = 2.2;
sprintf(OutputString,"%e or %f",Number,Number);

Then send OutputString out your serial port. Alternately, if you've
created a device so you can treat your serial port as a file, you can
use fprintf() to print directly to the serial port file, without using
the intermediary buffer.

Wim.
Hi Wajahat,

That shouldn't be too complex, you might want to use sprintf()
declared in with an appropriate format specification:

len = sprintf (buffer, "%14.7e", number);

Remember that the null character is stored at the end of the formatted
string, thus above statement would write 15 characters, but the value
of len is 14.

Rgds,

Andrew

> Subject: how toconvert floating point numbers to ASCII format
> Posted by: "w...@hotmail.com" w...@hotmail.com
> Date: Tue Jan 16, 2007 6:00 am ((PST))
>
> Hi i am new to dsp processing .I am using c6713.
> I want to output the floating point numbers to a modem.
> First i should convert these numbers to ASCII format.
> Any related document or sample code whould be helpful for me.
> Any response would be appreciated.
> Thanks
> wajahat
>