Parse
Converts hexadecimal (hex) variable(s) to decimal when type attribute is set to hex2vars and converts decimal variable(s) to hex when type is set to vars2hex. When using the parse command, vars must be predefined with the
set command by using the
type attribute (e.g. type=int16) so ComScript knows how many bytes to parse. See HexDecimalConversion example and the
Hex and Decimal conversion section for additional help.
Attributes:
hexvar: the name of the variable containing the hex string
vars: The comma-separated list of variable names
type: vars2hex to parse the variables into a hex variable, hex2vars to parse the hex variable into variables
Example:
<set var="0xNum1,0xNum2,0xNum3" type="byte,uint16,uint32" />
<!-- NOTE: the string below is actually just a text sting of hex letters and number so the type attribute defaults to text -->
<set var="HexString" value="FFAAAAF1E2D3C4"/>
<parse type="hex2vars" hexvar="HexString" vars="0xNum1,0xNum2,0xNum3" />
<log message="0xNum1(FF)=[0xNum1] in decimal" />
<log message="0xNum2(AAAA)=[0xNum2] in decimal" />
<log message="0xNum3(F1E2D3C4)=[0xNum3] in decimal" />
<parse type="vars2hex" hexvar="HexString2" vars="0xNum1,0xNum2,0xNum3" />
<log message="num1,num2 and mum3 backinto a hex string = [HexString2]" />
<!-- NOTE: Hex vars size must be defined with type for both hex2vars and vars2hex conversions -->
<set var="x,y,z" value="255,65534,-253" type="byte,uint16,int16" />
<parse type="vars2hex" hexvar="HexString3" vars="x,y,z" />
<log message="x,y,z in a hex string = [HexString3]" />
----
log command output:
0xNum1(FF)=255 in decimal
0xNum2(AAAA)=43690 in decimal
0xNum3(F1E2D3C4)=4058174404 in decimal
num1,num2 and mum3 back into a hex string = FFAAAAF1E2D3C4
x,y,z in a hex string = FFFFFEFF03