HEXTOI not working as expected
asadler
Junior Member
Hello all,
I'm having a thing happen with HEXTOI() that I can't explain and I'm certain it's some nuance of the function that I'm just not aware of. I've read the documentation in NetLinx Studio and I've searched the forums without luck, so here goes.
I have a string of hex values that I'm trying to parse and a specific byte in that string holds a value that I want. What I want to do is take that hex byte, which can be $00 or $01, convert it to an integer and store it into an integer array as either 0 or 1.
If I just take that bye and store it thusly:
nArrayName[nArrayIndex] = HEXTOI( MID_STRING( cMsg, 21, 1 ) ) // cMsg is the string of hex bytes
a value of 0 is stored even when the byte is $01
The only workaround I've found if you use an If-Else structure to check and see what the byte is and store the corresponding value. This seems really clumsy and I would really rather just store the integer equivalent of the hex value. What am I doing wrong? Thanks in advance.
I'm having a thing happen with HEXTOI() that I can't explain and I'm certain it's some nuance of the function that I'm just not aware of. I've read the documentation in NetLinx Studio and I've searched the forums without luck, so here goes.
I have a string of hex values that I'm trying to parse and a specific byte in that string holds a value that I want. What I want to do is take that hex byte, which can be $00 or $01, convert it to an integer and store it into an integer array as either 0 or 1.
If I just take that bye and store it thusly:
nArrayName[nArrayIndex] = HEXTOI( MID_STRING( cMsg, 21, 1 ) ) // cMsg is the string of hex bytes
a value of 0 is stored even when the byte is $01
The only workaround I've found if you use an If-Else structure to check and see what the byte is and store the corresponding value. This seems really clumsy and I would really rather just store the integer equivalent of the hex value. What am I doing wrong? Thanks in advance.
Comments
-
You've misunderstood what hextoi does.
It converts a STRING in the form
AB01
to the numeric value that the string represents in hexadecimal:
43777
For an intuitive example in a different setting, run Start / Programs / Accessories / Calculator, select View / Scientific, select Hex, type in AB01 then select Dec(imal).
Your byte is already contains the value you want; you just need to ram it into your integer. type_cast will do that for you:
PROGRAM_NAME='fred'
define_variable
integer ii
char ss[10]
define_program
wait 20
{
ss = "$02,$01,$03"
ii = type_cast(mid_string(ss,2,1))
send_string 0,"itoa(ii)"
} -
Ok, I get it now. I was reading the docs all wrong. Thanks very much for the help.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums