formatting data from Scrath Pad RAM
Jon Loldrup
Posts: 14
Hi
After loading some position-data from my GPS into SPRAM, I am wondering how to convert it to integers?
I can easily put it into the register:
myVariable VAR Byte
GET 0, myVariable
but when I want to convert it to integer:
myOtherVariable VAR Byte
myOtherVariable = DEC myVariable
I am not allowed [noparse]:([/noparse]
How can i EVER do calculations on a digit stored as ASCII-code? Poor me
(by the way, if I manage to convert it, and I want to substract two latitudes from each other, I will still have to implement the substraction-algorithm myself, looping through individual bytes containing the individual digits of the position, as a word cannot contain the whole position. Is there no easier way?)
/jon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
/jon
After loading some position-data from my GPS into SPRAM, I am wondering how to convert it to integers?
I can easily put it into the register:
myVariable VAR Byte
GET 0, myVariable
but when I want to convert it to integer:
myOtherVariable VAR Byte
myOtherVariable = DEC myVariable
I am not allowed [noparse]:([/noparse]
How can i EVER do calculations on a digit stored as ASCII-code? Poor me
(by the way, if I manage to convert it, and I want to substract two latitudes from each other, I will still have to implement the substraction-algorithm myself, looping through individual bytes containing the individual digits of the position, as a word cannot contain the whole position. Is there no easier way?)
/jon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
/jon
Comments
Note that you can also use DO ... LOOP and other neater constructs.
This stops at the first non-digit and leaves position at the address of
the next character after the delimiter. If you need a word value, just
define theValue as a word instead of a byte.
A complete article describing this can be found at the following link. Take care.
http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv103.pdf
also
http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv83.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Your query relates directly to some PBASIC enhancements I've begun lobbying for: http://forums.parallax.com/showthread.php?p=652397. As BASIC Stamps are used more and more to deal with serial protocols, it would be helpful if the language supported buffer transfers/encoding/decoding in a more I/O-like fashion. Mike's technique will certainly work, but with enhanced language features it wouldn't be necessary.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support