Converting bytes to Strings
dermot
Posts: 26
Hi,
Does anyone know how to convert bytes/words/longs to strings and strings to bytes/words/longs. Is there an object pre-written. I cant find any.
Does anyone know how to convert bytes/words/longs to strings and strings to bytes/words/longs. Is there an object pre-written. I cant find any.
Comments
If you want to make a string of bytes you could (in a DAT section), do this:
byte string1 "I"," ","a","m"," ","h","e","r","e",0 'notice each letter is handled as a byte
or more simply:
byte string1 "I am here",0
these two are handled the same way. Both can be handled as bytes or as a string.
I have an object (in my signature) that does string manipulation, if that is what you are looking for.
EDIT: Possibly you are looking to convert numeric values to strings? Then look for the "Simple_Numbers" object in the OBEX (this one, I think...it has a different name), but you already have it, because it came with the Propeller Tool.
Sorry for confusion I was indeed trying to convert numeric values to strings
It shows how to convert a value to ASCII characters.
Duane
I think there is also a string object somewhere which can also convert from string to number.
The ConfigReader object in the tools section also converts from string to number.
The Parallax Serial Terminal (PST) object has a very nice little method called StrToBase. Here's the method:
To bad it's a private method. I think it would be more useful if it had been a public method.
I just recently discovered this useful method; I thought I'd let others know about it.
Duane
Really simple if you are Ok with a HEX representation of the value.
each 4 bits will be the 0 to F, so just add 48 to it and if that result is higher than 57 add another 8 to it.
Dec is a little harder, but if you know your value will always be between 0-99 (two digits) then some shortcuts could be implemented.