Shop OBEX P1 Docs P2 Docs Learn Events
ASCII to Integer Help — Parallax Forums

ASCII to Integer Help

pathikgohil85pathikgohil85 Posts: 21
edited 2011-10-26 14:10 in BASIC Stamp
Can some one help me to a find resource for converting an ASCII string to an integer using PBASIC?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 14:10
    If the ASCII data is coming in from a device whose input statement supports it, use the DEC formatter. Otherwise you'll have to do the conversion yourself. If the ASCII character is in the byte variable X, you'd do X = X - "0" to get a numeric value between 0 and 9. If you're accumulating a decimal number from five successive ASCII digits, you could do

    answer = 0
    for i = 0 to 4
    answer = answer * 10 + (X(i) - "0")
    next

    Obviously, if the format of the number is more complex or if you need error checking, this would have to be more complex.
Sign In or Register to comment.