SPFE Documentation | Collections > SPFE Function Reference > hex-to-dec

Function: hex-to-dec

hex-to-dec(hex as xs:string) as xs:integer

Description

The hex-to-dec function takes are string representing a hexadecimal number and converts it to a decimal number.

Return value

Return type: xs:integer

The interger value of the hexadecimal number.

Source file

$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl

Parameters

hex

Type: xs:string

A string representing the hexadecimal number to be converted.

Definition

            <xsl:function name="sf:hex-to-dec" as="xs:integer">
		               <xsl:param name="hex" as="xs:string"/>

		               <xsl:variable name="len" as="xs:integer" select="string-length($hex)"/>
		               <xsl:choose >
			                   <xsl:when test="$len eq 0">
				                       <xsl:sequence select="0"/>
			                   </xsl:when>
			                   <xsl:when test="$len eq 1">
				                       <xsl:sequence select="      if ($hex eq '0')       then 0      else if ($hex eq '1')       then 1      else if ($hex eq '2')       then 2      else if ($hex eq '3')       then 3      else if ($hex eq '4')       then 4      else if ($hex eq '5')       then 5      else if ($hex eq '6')       then 6      else if ($hex eq '7')       then 7      else if ($hex eq '8')       then 8      else if ($hex eq '9')       then 9      else if ($hex = ('A', 'a')) then 10      else if ($hex = ('B', 'b')) then 11      else if ($hex = ('C', 'c')) then 12      else if ($hex = ('D', 'd')) then 13      else if ($hex = ('E', 'e')) then 14      else if ($hex = ('F', 'f')) then 15      else error(xs:QName('sf:hex-to-dec'))      "/>
			                   </xsl:when>
			                   <xsl:otherwise >
				                       <xsl:sequence select="      (16 * sf:hex-to-dec(substring($hex, 1, $len - 1)))      + sf:hex-to-dec(substring($hex, $len))"/>
			                   </xsl:otherwise>
		               </xsl:choose>
	           </xsl:function>