I need to convert an ascii string received by serin to a decimal number.
This code works in the simulator.
Although I get expected results, is there a better way to do it. Can you see any pitfalls
Thanks,
R.
This code works in the simulator.
Code:
#picaxe18m2
'Set up artificial string
eeprom 0,("1234")
do
read 0,b0,b1,b2,b3 'Read back ASCII values
sertxd (b0,b1,b2,b3,cr,lf)
pause 1000
'Convert ASCii to decimal
for bptr =0 to 3
@bptr=@bptr-48
next bptr
sertxd ("Decimal ",#b0," ",#b1," ",#b2," ",#b3,cr,lf)
pause 2000
'Scale place values
w2=b0*1000
w3=b1*100:w2=w2+w3
w3=b2*10:w2=w2+w3
w3=b3:w2=w2+w3
sertxd ("W2 = ",#w2,cr,lf)
pause 2000
loop
Thanks,
R.