miva_hex_decode()

 
Convert "data" to hexadecimal notation.
Syntax
miva_hex_decode( data )
returns the resulting decoded data
  • data = the hex data to decode.
User Annotations: miva_hex_decode
Ray Yates : rayyates at, pdqcoders d0t com
04/16/2018 09:00 a.m.
If you are looking for a way to convert a hexadecimal number to decimal, the function below will do that.
<MvFUNCTION NAME = "hex2dec" PARAMETERS = "num" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.num" VALUE = "{ toupper(trim(l.num)) }">
	<MvASSIGN NAME = "l.len" VALUE = "{ len(l.num) }">
	<MvIF EXPR = "{ l.len LT 1}">
		<MvFUNCTIONRETURN>
	</MvIF>

	<MvASSIGN NAME = "l.base" VALUE = "{ 1 }">
	<MvFOR INDEX = "l.pos" FIRST = "{ 1 }" LAST = "{ l.len }">
		<MvASSIGN NAME = "l.char_value" VALUE = "{ asciivalue(substring(l.num, l.len - l.pos + 1, 1)) }">

		<MvIF EXPR = "{ (l.char_value GE 48) AND (l.char_value LE 57) }">
			<MvASSIGN NAME = "l.dec_val" VALUE = "{ l.dec_val + ((l.char_value - 48) * l.base) }">

		<MvELSEIF EXPR = "{ (l.char_value GE 65) AND (l.char_value LE 70) }">
			<MvASSIGN NAME = "l.dec_val" VALUE = "{ l.dec_val + ((l.char_value - 55) * l.base) }">

		<MvELSE>
			<MvASSIGN NAME = "g.hex2dec_error" VALUE = "Error: Invalid hex characters found.">
			<MvFUNCTIONRETURN>
		</MvIF>

		<MvASSIGN NAME = "l.base" VALUE = "{ l.base * 16 }">
	</MvFOR>

    <MvFUNCTIONRETURN VALUE = "{ l.dec_val }">
</MvFUNCTION>