String to Integer and String to Float coversion in Basic stamp.
labheshr
Posts: 10
Hello Everyone:
I am working on a Bluetooth controlled Boe-Bot and need to accept strings (made using C++ program on PDA) via bluetooth. However after doing this I need to convert them to Float and Integer values and perform certain Boe-Bot actions using these values.
Example: I accept a using SERIN 0, 84,[noparse][[/noparse]certain variable and its extracted bytes (I dont know how to do this either)] on the Bluetooth port (EB500).
a
After doing this , I need to covert the string into integer values- if I received "120" , it should be converted to 120 in integer, since certain arithimatic calculation will be done on this. Similiarly when I receive "0.88" , it should become equivalent 0.88 in float.
Basically I am looking for an equivalent functionality of "atoi" and "atof" in Basic Stamp language.
Any help on this would be greatly appreciated!
Thanks;
Labhesh.
I am working on a Bluetooth controlled Boe-Bot and need to accept strings (made using C++ program on PDA) via bluetooth. However after doing this I need to convert them to Float and Integer values and perform certain Boe-Bot actions using these values.
Example: I accept a using SERIN 0, 84,[noparse][[/noparse]certain variable and its extracted bytes (I dont know how to do this either)] on the Bluetooth port (EB500).
a
After doing this , I need to covert the string into integer values- if I received "120" , it should be converted to 120 in integer, since certain arithimatic calculation will be done on this. Similiarly when I receive "0.88" , it should become equivalent 0.88 in float.
Basically I am looking for an equivalent functionality of "atoi" and "atof" in Basic Stamp language.
Any help on this would be greatly appreciated!
Thanks;
Labhesh.
Comments
It is possible to do scaled fixed point arithmetic where, for example, 0.88 is represented as 88 and 1.34 is represented as 134, but you'll have to code it yourself.· The compiler won't do it for you.
So basically, if I am sending string values to the Boe-Bot, the code to accept them and process them as integers would be of following kind:
The data coming in from Bluetooth is actually a text string. Because i have put DEC, it will be accepted by the compiler as a series of digits stored in Byte array szCmom.
Is this correct?
Also, then I can do operation on this data such as addition or comparison? For example: if ( szCom = angle) ... do something. IN this case angle is a decimal number.
Please confirm if this would work for me?
Otherwise I will have to convert the angle decimal to String format, which I do not know how to do?
Thank you;
Labhesh.
Once the SERIN is done, the integer value is in szCom and you can do whatever you want numerically with it.
That was great help!
-Labhesh.