XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Dominic VieiraSubject: Convert decimal to Hex.
Author: Dominic Vieira
Date: 28 Jun 2007 02:05 PM
Hi, is there a way to cast a decimal value to a hex value? For example, Decimal 177 convert to hex B1.

Thanks,
Dominic

Postnext
(Deleted User) Subject: Convert decimal to Hex.
Author: (Deleted User)
Date: 29 Jun 2007 04:15 AM
Hi Dominic,
there is not a built-in function to do that, but I wrote this user-defined function to do the job

declare function local:convertToHex($number as xs:integer) as xs:string
{
let $hexDigits:=('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
return
if($number < 16) then
$hexDigits[$number + 1]
else
fn:concat(local:convertToHex($number idiv 16), local:convertToHex($number mod 16))
};

Hope this helps,
Alberto

Posttop
Rittik BanikSubject: Convert decimal to Hex.
Author: Rittik Banik
Date: 22 Dec 2011 10:25 AM
Hi , this is what could be used for Hex to Decimal :
**********************************************************************
declare namespace functx = "http://www.functx.com";
declare namespace op ="http://www.w3.org/2001/12/xquery-operators";



declare function functx:chars
( $arg as xs:string? ) as xs:string* {

for $ch in string-to-codepoints($arg)
return codepoints-to-string($ch)
} ;


declare function functx:index-of-string
( $arg as xs:string? ,
$substring as xs:string ) as xs:integer* {

if (contains($arg, $substring))
then (string-length(substring-before($arg, $substring))+1,
for $other in
functx:index-of-string(substring-after($arg, $substring),
$substring)
return
$other +
string-length(substring-before($arg, $substring)) +
string-length($substring))
else ()
} ;


declare function local:power($a as xs:double, $b as xs:integer) as xs:double {
if($b < 0) then 1 div local:power($a, abs($b))
else if($b = 0) then 1
else if($b = 1) then $a
else local:power($a, $b mod 2) * local:power($a * $a, $b idiv 2)
};


declare function local:convertToDecimal($hexstr as xs:string , $value as xs:double) as xs:double
{
let $digits as xs:string:= "123456789ABCDEF"
let $length as xs:integer := fn:string-length($hexstr)
let $hexstr2 as xs:string* := functx:chars($hexstr)
let $value as xs:double := local:power( 16.00,(fn:string-length($hexstr) - 1 )) * functx:index-of-string($digits ,$hexstr2[1]) + $value
return

if($length = 1)
then $value
else
local:convertToDecimal(fn:substring($hexstr,2),$value)

};
local:convertToDecimal("A15", 0.00)

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.