Character To String
hylee101001
Posts: 48
Hello,
I'm trying to get a decimal number from a corresponding number and character comparison.
For example,
I tried to convert '1' to decimal 1
and
I tried to compare x to 'A'
(x := pst.CharIn)
But I do not know how I can do it. I'm confused with using byte array, which I just copied from internet and it doens't work.
This is my code:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
pst : "Parallax Serial Terminal"
str: "data"
num : "Numbers"
VAR
long value
byte changed
PUB main | charVar , a
num.Init
pst.Start(115200)
value := 0
repeat
if pst.RxCount > 0
pst.str(String("PRPLR sayz: received"))
charVar := pst.CharIn
pst.str(String("char is: "))
pst.char(charVar)
pst.newline
changed := char 2Dec(charVar)
pst.str(String("number is: "))
pst.Dec(changed)
pst.newline
PUB char 2Dec(charVar) | index
result := 0
repeat index from 0 to strsize(charVar)
result += byte[charVar-3][0]
I'm trying to get a decimal number from a corresponding number and character comparison.
For example,
I tried to convert '1' to decimal 1
and
I tried to compare x to 'A'
(x := pst.CharIn)
But I do not know how I can do it. I'm confused with using byte array, which I just copied from internet and it doens't work.
This is my code:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
pst : "Parallax Serial Terminal"
str: "data"
num : "Numbers"
VAR
long value
byte changed
PUB main | charVar , a
num.Init
pst.Start(115200)
value := 0
repeat
if pst.RxCount > 0
pst.str(String("PRPLR sayz: received"))
charVar := pst.CharIn
pst.str(String("char is: "))
pst.char(charVar)
pst.newline
changed := char 2Dec(charVar)
pst.str(String("number is: "))
pst.Dec(changed)
pst.newline
PUB char 2Dec(charVar) | index
result := 0
repeat index from 0 to strsize(charVar)
result += byte[charVar-3][0]
Comments