PDA

View Full Version : Decimal values from string



GioppY
- 6th November 2005, 10:42
Hi .
For many reason I can't use Hserin Timeout,Label,[dec par1,dec par2,dec par3] .
I have my serial input routine that receive ascii caracters and put them in a buffer.
There is a way to convince HSERIN to get data from buffer instead of serial port.
Or someone has a routine that scan the buffer and return the decimal values.

Regards
Gianni

BigWumpus
- 9th November 2005, 21:10
This is a way to the basics of digital calculation and base-conversion....

Why don't test your mind ?

Take a digit out of the Buffer (ASCII),
subtract "0" ($30),
take your Dummy-Variable, multiply it by 10, add the result from the last action...

Loop until there is an End or so....


f.eg.: (Quick and very dirty!)

Dummy=0
I=0
TakeThem:
Digit=Dummy[I]-$30:I=I+1
If (Digit>0) and (Digit<10) Then Dummy=Dummy*10+Digit:Goto TakeThem