PDA

View Full Version : Convert an integer to a string



GioppY
- 21st March 2007, 09:48
Hi.
I need something like serout [dec2 var_name] or lcdout dec var_name;
but send the result to a string.
I suppose these functions are available in the compiler; nobody knows how to call them ?
Thanks

mackrackit
- 21st March 2007, 11:33
Look at SEROUT2 in the manual. This tells how to send in BIN, HEX, DEC, or STR.

HenrikOlsson
- 21st March 2007, 11:42
Hi,
How about:


Serout......[#var_name]
LCDOUT $FE,1,[#var_name]


/Henrik Olsson.

GioppY
- 21st March 2007, 13:19
Perhaps i badly explained.
I do not use serout or lcdout; i need a 16 bit binary to decimal conversion; i have to send a variable value to the Nokia 3310 display.
I now realized that DIG may be useful.
Regards

Jerson
- 21st March 2007, 14:05
Hmm.. you are looking for an equivalent like the c function sprintf.

You are right, the DIG command is ideal to build the string. It may be more optimised if you hand code in asm

Jerson

skimask
- 21st March 2007, 15:50
Perhaps i badly explained.
I do not use serout or lcdout; i need a 16 bit binary to decimal conversion; i have to send a variable value to the Nokia 3310 display.
I now realized that DIG may be useful.
Regards

tenthousands = value / 10000
value = value - ( tenthousands * 10000 )
thousands = value / 1000
value = value - ( thousands * 1000 )
hundreds = value / 100
value = value - ( hundreds * 100 )
tens = value / 10
value = value - ( tens * 10 )
ones = value

string(4) = tenthousands + 48
string(3) = thousands + 48
string(2) = hundreds + 48
string(1) = tens + 48
string(0) = ones + 48

First chunk of code will get the decimal values for the place holder for that digit.

Second chunk of code will change that into an ASCII representation of that number.

Then you can just serout (or SPI or I2C or whatever) that 'string' out whatever port you need to...

Theoretically anyways...