RE: [xsl] numerical inconsistencies doing dec to hex conv.

Subject: RE: [xsl] numerical inconsistencies doing dec to hex conv.
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 10 Mar 2003 12:52:23 -0000
You're using a buggy XSLT processor.

This code works fine on Saxon 6.5.2 and Saxon 7.4.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Peter Doggett
> Sent: 10 March 2003 12:05
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] numerical inconsistencies doing dec to hex conv.
> 
> 
> Hi,
> 
> I am using the below template to convert a decimal number 
> into a hex number. It seems to work correctly apart from 
> when I want to calculate the hex equivelent of the decimal 
> number -  4294967295. This number is of particular 
> significance as in Hex this should be FFFFFFFF (a 32 bit, 
> bitmask; i am using xml to describe registers in h/w).
> The template outputs FFFFFFF0 abnd I dont know why.
> 
> The template seems to output the incorrect value for 
> 1099511627775, which is the decimal representation of 
> FFFFFFFFFF in hex.
> 
> The recursive template is as follows:
> 
> 
> <xsl:variable name="hexDigits" select="'0123456789ABCDEF'" />
>   <xsl:template name="toHex">
>     <xsl:param name="decimalNumber" />
>     <xsl:if test="$decimalNumber >= 16">
>       <xsl:call-template name="toHex">
>         <xsl:with-param name="decimalNumber" 
> select="floor($decimalNumber div 16)" />
>       </xsl:call-template>
>     </xsl:if>
>     <xsl:value-of select="substring($hexDigits, 
> ($decimalNumber mod 16) + 1, 1)" />
> </xsl:template>
> 
> Can anybody figure out why this is happening or have an 
> equivelent template that can calculate the conversion 
> correctly?
> 
> 
> Thankyou for your time.
> 
> 
> ----------------------
> Peter Doggett
> ee99ppd@xxxxxxxxxxxx
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread