Home AMX User Forum NetLinx Studio

HEXTOI not working as expected

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.

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.
Sign In or Register to comment.