Convert "string" to number
dk_akj
Posts: 37
Hi,
I have a received some data via seriel interface.
The data is stored in an array (MSG \8)
The data is always nummeric. ie 00000360
the first 4 chars·is always 0
How do i convert the last 4 chars to a numeric word ie 360·??
Kind regards
Anders
I have a received some data via seriel interface.
The data is stored in an array (MSG \8)
The data is always nummeric. ie 00000360
the first 4 chars·is always 0
How do i convert the last 4 chars to a numeric word ie 360·??
Kind regards
Anders
Comments
for x = 3 to 0
debug dec(x) ? data
next
i'm not too sure about that one - you'll have to try it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Try the Stamp Tester
http://hometown.aol.com/newzed/index.html
·
This gives an error
SERIN PinRx, Baud,Bad_Data,5000,no_data , [noparse][[/noparse]WAIT("," ),SKIP 1, dec8 limit ]
This doesnt work:
SERIN PinRx, Baud,Bad_Data,5000,no_data , [noparse][[/noparse]WAIT("," ),SKIP 1, dec limit ]
Anders
Try this:
serin pin, baud, 5000, no_data, [noparse][[/noparse]WAIT(","),· dec8 limit]
I don't think you can use Bad Data and no data in the same command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Try the Stamp Tester
http://hometown.aol.com/newzed/index.html
·
if you are still having trouble, did you check your baud rates?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Try the Stamp Tester
http://hometown.aol.com/newzed/index.html
·
Assuming that you're successfully receiving the string (of eight characters), here's how you can extract the last four characters as a numeric value:
Get_Value:
· value = 0
· FOR idx = 4 TO 7
··· value = value * 10
··· value = value + (msg(idx) - "0")
· NEXT
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 9/30/2004 10:12:40 PM GMT
Sid
msg············ VAR···· Byte(8)
idx············ VAR···· Nib
value·········· VAR···· Word
Reset:
· DEBUG CLS, "Enter a value (8 digits): "
Main:
· DEBUGIN STR msg\8
· value = 0
· FOR idx = 4 TO 7
··· value = value * 10
··· value = value + (msg(idx) - "0")
· NEXT
· DEBUG CRSRXY, 0, 2, DEC value
· END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
//akj