Shop OBEX P1 Docs P2 Docs Learn Events
Converting 3 bit ASCII to a decimal (Byte) num — Parallax Forums

Converting 3 bit ASCII to a decimal (Byte) num

ArchiverArchiver Posts: 46,084
edited 2004-02-23 08:29 in General Discussion
Eric-

Here's another way to approach the problem that may work for you.
If the values you are reading actually represent 0-255, and you know
you're going to get three ASCII digits each reading, why not read
the data directly into your byte variable? If "reading" is your
byte variable:

SERIN pin,baud,[noparse][[/noparse] DEC3 reading ]

That will handle the ASCII-to-numeric value conversion for you. To
then send the data in ASCII form to your PC:

SEROUT pin,baud,[noparse][[/noparse] DEC3 reading ]

That will re-create the 3-byte ASCII stream for transmission and
"reading" will retain the 0-255 value.

This approach uses some of the Stamp's built-in capabilities to do
the conversions for you, any you avoid the SPRAM and manual
conversion overhead.

Regards,

Steve
Sign In or Register to comment.