Hex value to Integer
javedwahid
Posts: 37
I have a string where I'm parsing out 1 character at a time. The first character is $22, when I try and use HEXTOI(char) I get an error, I think it's because $22 is not a literal string which is what it looks like HEXTOI needs to do the conversion per the documentation.
Is there any other way to convert $22 to an Integer? How would this be done?
Thanks,
J
Is there any other way to convert $22 to an Integer? How would this be done?
Thanks,
J
0
Comments
But where it really gets hairy is that we are never actually typing in those values in any form, as there is another layer of abstraction: ASCII. Everything you type on a computer is an ASCII code representing the value, and there is something in the notation to tell the compiler how you want it translated. In the AMX world, enclosing it in single spaces tells the compiler, "I am typing it in ASCII, and I want you to send the ASCII values directly", which is how we do text and string variables. If I type in numerals, I'm telling it, "I am typing in ASCII, but I am representing my numbers in decimal, so translate it as such" If I put a $ in front of it, it's hex instead of decimal, but it's all just a way of telling the compiler how to translate what I am typing. They are all interchangeable as long as the device is getting the values it expects.
Every now and then, just to thoroughly confuse people, a protocol is written so that the device is actually asking for the ASCII representation of the hex value, not the actual hex value. Some also may want the ASCII representation of the decimal value too, which is more common. In both those cases, you are sending the ASCII directly, with whatever notation the device requires to translate it properly. In those cases, you type enclosed in single quotes, and those are the cases you might want to use functions like ITOHEX(), which returns an ASCII with hex notation string for a numeric value represented in hex. However, it is very important to be sure that is what they really want. Most of the time, they really just want the value itself. I won't even get into the protocols that are poorly documented and don't really tell you what they want ...
Clear as mud, eh? Maybe someone else can chime in who is better at explaining.