Really dumb question involving character arrays
firestorm.v1
Posts: 94
I'm really embarassed to be asking, but I haven't been able to find a solution on this. I'm working with an array as shown trying to extract the characters and convert them into numbers. The array is not populated like this in the program but is read from SERIN to the inputArray array. I can read, and DEBUG the results, but DEBUG DEC inputArray(4) shows the ASCII code for the character "2" not the value 2.
inputArray(3)="1"
inputArray(4)="2"
inputArray(5)="0"
inputArray(6)="3"
How do I convert "1" into the digit 1 so I can do some variable testing with it? Right now if I try to show it, it returns the ASCII code for it. I am needing to do this for several elements on this array but if I can get this one down, the others will fall into place.
Thank you for your help, a schematic and code will be posted once the display is complete. [noparse]:)[/noparse]
Matt
P.S. I managed to figure out how to use the serial port You can use pin 16 for the DEBUG port for serial communications. My application uses SEROUT 16,16468,[noparse][[/noparse]"X1"] in order to send "X1" out the serial port on the BS2 homework board at 9600,n,8,1
inputArray(3)="1"
inputArray(4)="2"
inputArray(5)="0"
inputArray(6)="3"
How do I convert "1" into the digit 1 so I can do some variable testing with it? Right now if I try to show it, it returns the ASCII code for it. I am needing to do this for several elements on this array but if I can get this one down, the others will fall into place.
Thank you for your help, a schematic and code will be posted once the display is complete. [noparse]:)[/noparse]
Matt
P.S. I managed to figure out how to use the serial port You can use pin 16 for the DEBUG port for serial communications. My application uses SEROUT 16,16468,[noparse][[/noparse]"X1"] in order to send "X1" out the serial port on the BS2 homework board at 9600,n,8,1
Comments
Remove the quotes, like this:
inputArray(4) = 2
The quotes tell the editor to view whatever is inside as ASCII.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
DEBUG DEC InputArray(4)-48
Another way is to use SERIN to do the conversion
SERIN ,,,[noparse][[/noparse]DEC1 inputArray(0),DEC1 inputArray(1),...]
but that would work only at slower baud rates.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Refresh my memory, but you can store a single character in a Byte, correct?
intValue = InputArray(4) - "0"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
So MyVal = "2" puts the ascii value of "2" (42?) in MyVal
DEBUG DEC MyVal takes that 42, and outputs it as "42".
DEBUG MyVal would output "2".
Thanks for all your help, I couldn't have done it without it.