View Full Version : ASCII to Decimal converter
07-22-2009, 10:35 AM
does anyone have a simple ascii to decimal converter, i really dont want to have to spend the time to write one since i dont have much time to work with the prop. i know it wouldnt be hard, but i thought id ask.
07-22-2009, 10:45 AM
It's tragic that one who claims to be a "science geek" would deny themselves the learning opportunity to create an algorithm. Oh, well, your laziness is to my benefit -- I don't need this method now but I might need it later.
[ Edit ] : After futzing around with my own code I found a C function on the Internet that was more elegant and translated it to Spin.
pub atol(pntr) | value, pos, c
'' Converts string at pointer to signed long
value := 0 ' clear result
if (byte[pntr] == "-") ' if 1st char "-"
pos := false ' mark
pntr++ ' advance pointer
pos := true
repeat while ((c := byte[pntr++]) > 0) ' get a character
if (c => "0") and (c =< "9") ' valid?
value := (value * 10) + (c - "0") ' yes, add to result
quit ' no, abort loop
Post Edited (JonnyMac) : 7/22/2009 2:34:23 PM GMT
07-22-2009, 10:48 AM
If you mean to simply display the decimal value of a character all you have to do is - "G" put the character in quotes.
debug("G") will pass the decimal value of G, which is 71 to the debug method.