Integer (DEC) to String Conversion.
Boris
Posts: 81
I have a BYTE-size variable with an integer 0 -> 255 written in it (variable Temp, for example)
what i need to do is use that number in a SERIN (WAIT)·command, in a loop.
The wait qualifier will have a 3 set charachters (ABC)·and variable Temp appeneded to it. If i leave Temp as an integer basic stamp will convert it to an ASCII charachter. But i need it to wait for ABC25, ABC26, ABC27, etc...
or 3 digit ABC134, ABC135, 136,137,138...
There does not appear to be a String command to automatically convert DEC to String.
I came up with this pretty complicated procedure:
1) Find out number of digits (0 to 9-1, 10 to 99-2, 100 to 255-3)
2) Take each digit, one at a time,·(depending on number of digits), and add 48 to it, to convert to ASCII character equal to that number, then write the ASCII character into Temp2(0 to 3).
3) Now here is the problem, if i just leave Temp2 as is,·consisting of·3 bytes, and do WAIT("ABC",Temp), then if the original integer was less than 100 (lets say it was 2 digits), the command will actually wait for ABC0##, i need it to WAIT for ABC##
The integer to decimal conversion seems like a pretty simple and common process.
Any ideas on how to complete step 3 of my logic? or
Is there an already written code that does this?
Thank you,
Boris.
what i need to do is use that number in a SERIN (WAIT)·command, in a loop.
The wait qualifier will have a 3 set charachters (ABC)·and variable Temp appeneded to it. If i leave Temp as an integer basic stamp will convert it to an ASCII charachter. But i need it to wait for ABC25, ABC26, ABC27, etc...
or 3 digit ABC134, ABC135, 136,137,138...
There does not appear to be a String command to automatically convert DEC to String.
I came up with this pretty complicated procedure:
1) Find out number of digits (0 to 9-1, 10 to 99-2, 100 to 255-3)
2) Take each digit, one at a time,·(depending on number of digits), and add 48 to it, to convert to ASCII character equal to that number, then write the ASCII character into Temp2(0 to 3).
3) Now here is the problem, if i just leave Temp2 as is,·consisting of·3 bytes, and do WAIT("ABC",Temp), then if the original integer was less than 100 (lets say it was 2 digits), the command will actually wait for ABC0##, i need it to WAIT for ABC##
The integer to decimal conversion seems like a pretty simple and common process.
Any ideas on how to complete step 3 of my logic? or
Is there an already written code that does this?
Thank you,
Boris.
Comments
It's easy to create a subroutine to build the string to wait for ... like this:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 10/19/2004 10:20:52 PM GMT
what is variable wLen used for?
And the SERIN command will look like this?
SERING Rpin, baudmode,[noparse][[/noparse]WAITSTR wstr]
so if idx=>100 wstr will be "###", 2 digits it will be "##" or "## "? 1 digit "#" or "#· "
Thanks for your input.
SERIN pin, baud, [noparse][[/noparse]WAITSTR wStr\wLen]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office