Convert to ascii
by c-level · in Torque Game Engine · 03/13/2007 (9:29 am) · 1 replies
I've got TGE sending serial data out to a device. It's cool, when it's done, we'll post.
It's anticipating ascii values, so I need to convert to that.
With this post...
http://www.garagegames.com/blogs/32/10202
...I see how to convert my numbers to ascii if the values aren't part of the 1st 32 characters.
I need to be able to send any number between 1 and 127. As ascii. How can I produce these values? (Yes, I'm new to any ascii dilemma).
It's anticipating ascii values, so I need to convert to that.
With this post...
http://www.garagegames.com/blogs/32/10202
...I see how to convert my numbers to ascii if the values aren't part of the 1st 32 characters.
I need to be able to send any number between 1 and 127. As ascii. How can I produce these values? (Yes, I'm new to any ascii dilemma).
About the author
Torque Owner Mike Henry
Is the input to the function a string of numbers, so: "68 79 71" would return "DOG".
Or is the input just a plain ascii string, so: "DOG" would return "DOG.
It looks like the second one, which doesn't seem to do anything useful except to
remove values below 32 and above 129, which could be done with a simple IF statement.
If you want to keep those values, then
(a) don't use this function, just use the string as is.
(b) make a function with IF statements to suit your needs.
(c) modify this function by adding the first 32 characters to the %charTable, and remove the line V=V+32.
Personally, I would use his function and add an IF statement for each special character I needed.
------------------------------
Condensed from Harold Brown, Apr 06, 06:
function chrValue(%chr){
%charTable = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~\t\n\r";
%value = strpos(%charTable,%chr);
%value = %value + 32;
}