Number to String
Hi all,
I was wondering if anyone knew of a way to convert a number (such as a byte or long value) into a string. Normally in another programming language like BASIC you would just use STR$(Value) and bam, job's done, but in Spin, I can't seem to get it to work...
I'm building an RFID storage system and I need to store the RFID codes I scan into a text file on a flashcard and no matter what I do I can't get it to save the numbers into the text file...
Any ideas?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?
I was wondering if anyone knew of a way to convert a number (such as a byte or long value) into a string. Normally in another programming language like BASIC you would just use STR$(Value) and bam, job's done, but in Spin, I can't seem to get it to work...
I'm building an RFID storage system and I need to store the RFID codes I scan into a text file on a flashcard and no matter what I do I can't get it to save the numbers into the text file...
Any ideas?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?

Comments
PUB ToStr(Num, Format): StrAddr {{Convert long Num to z-string using Format; returns string address. PARAMETERS: Num = 32-bit signed value to translate to ASCII string. Format = Indicates output format: base, width, grouping, etc. See "FORMAT SYNTAX" for more information. RETURNS: Actual length of output string, not including null terminator.}} BCXToText(Format >> 19 & 7, Format >> 13 & $3F, Format >> 12 & 1, Format >> 11 & 1, Format >> 5 & $3F, BinToBCX(Num, Format & $1F #> 2 <# 16)) StrAddr := @StrBufThe simplest version, in pseudo code:
byte buffer[noparse][[/noparse] 10 ] // Build a buffer of number characters, from the one's place to the higher ones... int index = 0 do { buffer[noparse][[/noparse] index ] = '0' + (value % 10) index += 1 value /= 10 } while( value > 0 ) // now print the digits from index-1 down to 0 (the number is reversed to simplify the implementation)Added: or yeah, what Sylvie said. [noparse]:)[/noparse]
One of my preferred for simple tasks is simple_numbers
obex.parallax.com/objects/182/
Numbers is the bigger brother, but sometimes is overkill. Formatting is more powerful, but more complex.
obex.parallax.com/objects/23/
Massimo
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?