Parsing Hex Strings
What is a recommended way to parse hex from a hex string? I am trying to do a remove_string where I remove the first byte of a 4 byte string, where it looks like this: ,$00,$04,$23,$D0. I want to remove each section and place it into its own array dimension, like so:
array[1] = ,$00 array[2] = ,$04 array[3] = ,$23 array[4] = ,$D0My goal here is to be able to ultimately calculate these hex values into decimal, and add them all together. However, the problem I am currently having is that when I try to do this:
local_var char sTesting[5] sTesting = (REMOVE_STRING(sProjInput,',',1))I get no response when I debug. I tried using the double quotes, which is what I am using to strip the first portion of the command response:
REMOVE_STRING(sProjInput,"$40,$03,$00,$0D",1)but I get a compiler error.
0
Comments
So in your situation, if you are simply wanting a string exploded into an array of individual character you don't actually have to do anything, you can simply use:
Hope this helps.
// 1 2 3 4 5 6 7 8 9 10 11 12 TEMP = "$48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64,$21" fnDoHandleTemp(TEMP) ; DEFINE_FUNCTION fnDoHandleTemp(CHAR iTEMP[]) { STACK_VAR CHAR RX_DATA_COPY[24] ; STACK_VAR CHAR RX_DATA_REMOVE[24] ; STACK_VAR CHAR RX_DATA_4BYTES[24] ; STACK_VAR INTEGER nLen ; STACK_VAR INTEGER i ; nLen = LENGTH_STRING(iTEMP) ; //THIS RX_DATA_4BYTES = GET_BUFFER_STRING(iTEMP,4) ; //OR RX_DATA_4BYTES = LEFT_STRING(iTEMP,4) ; //OR for(i = 1 ; i<= nLen ; i++)//COPY { RX_DATA_COPY[i] = iTEMP[i] ;//COPIES THE STRING } //OR for(i = 1 ; i<= nLen ; i++)//PAC MAN { RX_DATA_REMOVE[i] = GET_BUFFER_CHAR(iTEMP) ;//EATS THE STRING } //OR SELECT { ACTIVE(iTEMP[1] == $48): { //do something } ACTIVE(iTEMP[8] == $6f): { //do something } ACTIVE(iTEMP[2] == $65 && iTEMP[12] == $21): { //do something } } }Much like a char. (char = 8bit, integer = 16bit ...)
So, let's say you have the following Hex String:
string: "$4E, $32, $8A, $0D"
You don't need a multidimensional array to store these values.
char copy_string[4]
copy_string[1] = string[1]
copy_string[2] = string[2]
copy_string[3] = string[3]
copy_string[4] = string[4]
You don't need to make a
char copy_string[4][2]
string to acommodate those Hex values