Character to decimal? (Newbie)

bz26

New Member
By using the ASCII table, how do I convert user input in the terminal window from character to decimal? Here is a part of my code.

Code:
	sertxd("Waiting for user input: ", cr, lf)
	serrxd #userInputChar						;the # sign means char
	sertxd("The character you entered is ", #userInputChar, ". ")
So my variable userInputChar is now seen as a character. But by the ASCII table, it is also a decimal value. How can I display that decimal value? Is there a character to decimal conversion function? I know this is a really newbie question, I am new to programming.

Thanks for any help.
 

westaust55

Moderator
Try removing the hash symbol in the serrxd command. Having that the input expects only 0-9 and any non digit characters are treated as a terminator and ignored.
 

SAborn

Senior Member
Try sending the txd without using the # before "userInputChar, As the # converts the decimal value to ASCII.
 

jims

Senior Member
Try sending the txd without using the # before "userInputChar, As the # converts the decimal value to ASCII.
When running this code with the PE6 simulation it looks as if the # shows decimal. What am I missing?? JimS
Code:
 Main:
	b0=65
	sertxd("# shows: ", #b0,cr,lf)
	sertxd("NOT # shows: ", b0,cr,lf)
	stop
 

grim_reaper

Senior Member
When running this code with the PE6 simulation it looks as if the # shows decimal. What am I missing?? JimS
Code:
 Main:
	b0=65
	sertxd("# shows: ", #b0,cr,lf)
	sertxd("NOT # shows: ", b0,cr,lf)
	stop
From the manual...

The # symbol allows ASCII output. Therefore #b1, when b1 contains the data 126, will output the ascii characters "1" "2" "6" rather than the raw data 126. The # symbol can also be used with word, bit and input pin variables. - See more at: http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/sertxd/#sthash.OopIZz8L.dpuf
SerTxd will only ever write ASCII characters - the difference between # and non-# is that with the # the value in the variable (65 in this case) is translated into the two characters '6' and '5'. If you are storing 'a letter' in a variable, then you don't need the # symbol to transmit them. The # is used to show the 'raw' value, converted to displayable numbers for your convenience.

Reading that back has just muddled my brain.. but I'm sure it'll be helpful to someone...
 

inglewoodpete

Senior Member
Off track?

This thread seems to have gone off track.

The original question was about SerRxd Ie the PICAXE RECEIVING ASCII and turning it into binary for storing/processing in the PICAXE.

The last few posts all appear to relate to SerTxd (the PICAXE sending values as ASCII digits) - not what the OP was asking about. If you have queries on a different subject, please start your own thread. It can be very confusing, especially for beginners.
 

hippy

Technical Support
Staff member
It can be very confusing, especially for beginners.
It can be. The OP did ask how to display the decimal value of the character received, but the issue lies (probably) with the receive.

SERRXD variable

This will receive a single byte. If "A" is pressed on a keyboard and that is sent, the variable will hold that "A", which also has the value of 65. Whether that is "A", 65, $41 or %01000001 simply depends how one wants to describe it.

SERTXD ( variable )

Will send a single byte out and the terminal will show the appropriate letter or symbol when received and put on a display. If the variable contains an "A", 65, $41 or %01000001, then an "A" will be shown.

SERTXD( #variable )

Will send the variable's value as a sequence of bytes which will show the value as readable digits of a decimal number. If the variable contains an "A", 65, $41 or %01000001, the output will be "6" then "5".

SERRXD #variable

Will take a series of "0" to "9" bytes which are converted into a number which is stored in the variable when a terminating non-digit byte is received. So if "6" and "5" then "X" were sent, the variable would hold the value 65.
 

jims

Senior Member
Thank you Hippy...your detailed explanation helps. It would be nice to see things like this in the documents/manuals. Jim
 
Top