repalce of convert:string-to-hex()
Hello,
what will be the replacement of "convert:string-to-hex" in BaseX13?
Thanks.
Marco.
Hi Marco,
You can visit [1] to see the BaseX 13 replacement functions. In the latest snapshot, we have revised the error message; it now points to the new function and option names as well.
Ciao, Christian
Quoted text · Marco Lettere · 8 lines
Marco Lettere via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Montag, 26. Oktober 2026 um 16:24: > Hello, > > what will be the replacement of "convert:string-to-hex" in BaseX13? > > Thanks. > > Marco.
In what is perhaps a related question, convert:integer-to-base(0x20,10) does the thing and convert:integer-to-base(32,16) does the thing but is there a way to type a variable as being in hex? I don't think the type model allows for anything like
let $hex as xs:hexadecimal := 0x20but would be delighted to be wrong.
Thanks! Graydon
Quoted text · Christian Grün · 22 lines
On Tue, Oct 27, 2026, at 10:19, Christian Grün via BaseX-Talk wrote: > Hi Marco, > > You can visit [1] to see the BaseX 13 replacement functions. In the latest snapshot, we have revised the error message; it now points to the new function and option names as well. > > Ciao, > Christian > > [1] https://docs.basex.org/13/Conversion_Functions <https://docs.basex.org/13/Conversion_Functions?highlight=convert%20string%20to%20hex> > > > Marco Lettere via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Montag, 26. Oktober 2026 um 16:24: >> Hello, >> >> what will be the replacement of "convert:string-to-hex" in BaseX13? >> >> Thanks. >> >> Marco. >> >> >>
Quoted text · Graydon Saunders · 30 lines
Graydon Saunders <graydonish at fastmail.com> schrieb am Dienstag, 27. Oktober 2026 um 15:36: > In what is perhaps a related question, convert:integer-to-base(0x20,10) does the thing and convert:integer-to-base(32,16) does the thing but is there a way to type a variable as being in hex? I don't think the type model allows for anything like > > let $hex as xs:hexadecimal := 0x20 > > but would be delighted to be wrong. > > Thanks! > Graydon > > On Tue, Oct 27, 2026, at 10:19, Christian Grün via BaseX-Talk wrote: > >> Hi Marco, >> >> You can visit [1] to see the BaseX 13 replacement functions. In the latest snapshot, we have revised the error message; it now points to the new function and option names as well. >> >> Ciao, >> Christian >> >> [1] [https://docs.basex.org/13/Conversion_Functions](https://docs.basex.org/13/Conversion_Functions?highlight=convert%20string%20to%20hex) >> >> Marco Lettere via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Montag, 26. Oktober 2026 um 16:24: >> >>> Hello, >>> >>> what will be the replacement of "convert:string-to-hex" in BaseX13? >>> >>> Thanks. >>> >>> Marco.
Hi Christian,
I didn't ask that clearly; apologies.
I'm wondering if there's an XPath-and-XQuery type in 4.0 for hexadecimal values like U+hhhh format Unicode code points; something that will be the argument of "as" in a declaration like
let $test as xs:hexadecimal := 0x20There's xs:hexBinary but that's not the same thing. xs:integer(0x20) gives me 32, which is expected, but I think it tells me 0x20 isn't an integer as such.
I don't think any such type exists but was curious.
Thanks! Graydon
Quoted text · Christian Grün · 41 lines
On Tue, Oct 27, 2026, at 13:53, Christian Grün wrote: > Hi Graydon, > > The shortest way to do it is `bin:hex('20')`. > > Best, > Christian > > > Graydon Saunders <graydonish at fastmail.com> schrieb am Dienstag, 27. Oktober 2026 um 15:36: >> In what is perhaps a related question, convert:integer-to-base(0x20,10) does the thing and convert:integer-to-base(32,16) does the thing but is there a way to type a variable as being in hex? I don't think the type model allows for anything like >> >> let $hex as xs:hexadecimal := 0x20 >> >> but would be delighted to be wrong. >> >> Thanks! >> Graydon >> >> On Tue, Oct 27, 2026, at 10:19, Christian Grün via BaseX-Talk wrote: >>> Hi Marco, >>> >>> You can visit [1] to see the BaseX 13 replacement functions. In the latest snapshot, we have revised the error message; it now points to the new function and option names as well. >>> >>> Ciao, >>> Christian >>> >>> [1] https://docs.basex.org/13/Conversion_Functions <https://docs.basex.org/13/Conversion_Functions?highlight=convert%20string%20to%20hex> >>> >>> >>> Marco Lettere via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Montag, 26. Oktober 2026 um 16:24: >>>> Hello, >>>> >>>> what will be the replacement of "convert:string-to-hex" in BaseX13? >>>> >>>> Thanks. >>>> >>>> Marco. >>>> >>>> >>>>
Hi Graydon,
Quoted text · Graydon Saunders · 3 lines
> I'm wondering if there's an XPath-and-XQuery type in 4.0 for hexadecimal values like U+hhhh format Unicode code points > … > There's xs:hexBinary but that's not the same thing. xs:integer(0x20) gives me 32, which is expected, but I think it tells me 0x20 isn't an integer as such.
The query 0x20 results in a single item of type xs:integer, so 0x20 and xs:integer(0x20) is equivalent. This also means that the following let clauses would inevitably do the same thing:
let $test as xs:hexadecimal := 32
let $test as xs:hexadecimal := 0x20
let $test as xs:hexadecimal := xs:integer(0x20)What would you expect xs:hexadecimal to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation?
Best, Christian
Hi Christian,
Quoted text · Christian Grün · 1 line
> What would you expect xs:hexadecimal to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation?
Yes. (I think a hexadecimal value is an integer with a hexadecimal representation.) Trying to think about it carefully, I'd expect three things: 1. any literals assigned to a variable of type xs:hexadecimal must use the 0x prefix; assigning 0x20 is OK, assigning 32 is an error. 2. 'U+' || 0x20 would give U+20 instead of the U+32 it currently gives (if I want U+0020 I need to use format-integer to zero-pad, same as decimal integers 3. let $test as xs:hexadecimal := 0x20 + 0xA0 return $test would give 0xC0 (the $x in "for $x in (0x20 to 0x40) return 'U+' || $x" would be implicitly xs:hexadecimal and return U+20, etc.) This is very much a convenience; it's not hard to write a function to produce a hexadecimal representation. But there have been times it would have been a notably welcome convenience, and it's hard to avoid thinking that the language-level version would be more efficient.
thanks! Graydon
Quoted text · Christian Grün · 19 lines
On Tue, Oct 27, 2026, at 14:35, Christian Grün wrote: > Hi Graydon, > >> I'm wondering if there's an XPath-and-XQuery type in 4.0 for hexadecimal values like U+hhhh format Unicode code points >> … >> There's xs:hexBinary but that's not the same thing. xs:integer(0x20) gives me 32, which is expected, but I think it tells me 0x20 isn't an integer as such. > > The query `0x20` results in a single item of type `xs:integer`, so `0x20` and `xs:integer(0x20)` is equivalent. This also means that the following let clauses would inevitably do the same thing: > > let $test as xs:hexadecimal := 32 > let $test as xs:hexadecimal := 0x20 > let $test as xs:hexadecimal := xs:integer(0x20) > > What would you expect `xs:hexadecimal` to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation? > > Best, > Christian > >
On Tue, 27 Oct 2026 21:07:27 -0400 Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de>
Quoted text · Graydon Saunders · 5 lines
wrote: > Trying to think about it carefully, I'd expect three > things: 1. any literals assigned to a variable of type xs:hexadecimal > must use the 0x prefix; assigning 0x20 is OK, assigning 32 is an > error.
For XSD this could be a facet, but i think it’d have to be on a string type, alas.
You are also wanting hex constants, which seems not unreasonable, since XPath 4 has them already :)
But i would expect to be able to write
let $amt as xs:integer := 0xff * 3
return printf("%x", $amt)(for example).
Hexadecimal is about how an integer is represented, not how it’s stored.
(lets not think about hexadecimal floats!)
Hi Graydon,
As Liam has indicated, 0x20 and 32 is the same thing; it’s just another way to write an integer. This is basically what other programming languages have been providing for a long time. This means at the same time that it won’t be possible to differentiate between both when casting or coercing items.
One addition, which is at least related to your second expectation: With format-integer, numbers can now be output with different bases:
for $n in (32, 0x20, 0b100000)
return 'U+' || format-integer($n, '16^xxxx')Best, Christian
Quoted text · Graydon Saunders · 38 lines
Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Mittwoch, 28. Oktober 2026 um 02:08: > Hi Christian, > >> What would you expect xs:hexadecimal to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation? > > Yes. (I think a hexadecimal value is an integer with a hexadecimal representation.) > Trying to think about it carefully, I'd expect three things: > > - any literals assigned to a variable of type xs:hexadecimal must use the 0x prefix; assigning 0x20 is OK, assigning 32 is an error. > - 'U+' || 0x20 would give U+20 instead of the U+32 it currently gives > (if I want U+0020 I need to use format-integer to zero-pad, same as decimal integers > - let $test as xs:hexadecimal := 0x20 + 0xA0 return $test would give 0xC0 > (the $x in "for $x in (0x20 to 0x40) return 'U+' || $x" would be implicitly xs:hexadecimal and return U+20, etc.) > > This is very much a convenience; it's not hard to write a function to produce a hexadecimal representation. But there have been times it would have been a notably welcome convenience, and it's hard to avoid thinking that the language-level version would be more efficient. > > thanks! > Graydon > > On Tue, Oct 27, 2026, at 14:35, Christian Grün wrote: > >> Hi Graydon, >> >>> I'm wondering if there's an XPath-and-XQuery type in 4.0 for hexadecimal values like U+hhhh format Unicode code points >>> … >> >>> There's xs:hexBinary but that's not the same thing. xs:integer(0x20) gives me 32, which is expected, but I think it tells me 0x20 isn't an integer as such. >> >> The query 0x20 results in a single item of type xs:integer, so 0x20 and xs:integer(0x20) is equivalent. This also means that the following let clauses would inevitably do the same thing: >> >> let $test as xs:hexadecimal := 32 >> let $test as xs:hexadecimal := 0x20 >> let $test as xs:hexadecimal := xs:integer(0x20) >> >> What would you expect xs:hexadecimal to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation? >> >> Best, >> Christian
Hi Christian,
I have no argument with 0x20 and 32 being the same thing;   and the contents of " " and the CDATA escaped version of a space are the same thing, too. It's sometimes useful to be able to write them in different ways.
Having format-integer() understand bases solves what I see as the main problem (my homemade convert-to-hex-representation function is unlikely to be as reliable as a language feature) and is welcome news.
thank you! Graydon
Quoted text · Christian Grün · 50 lines
On Wed, Oct 28, 2026, at 14:09, Christian Grün wrote: > Hi Graydon, > > As Liam has indicated, 0x20 and 32 is the same thing; it’s just another way to write an integer. This is basically what other programming languages have been providing for a long time. This means at the same time that it won’t be possible to differentiate between both when casting or coercing items. > > One addition, which is at least related to your second expectation: With format-integer, numbers can now be output with different bases: > > for $n in (32, 0x20, 0b100000) > return 'U+' || format-integer($n, '16^xxxx') > > Best, > Christian > > > Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Mittwoch, 28. Oktober 2026 um 02:08: >> Hi Christian, >> >> > What would you expect xs:hexadecimal to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation? >> >> Yes. (I think a hexadecimal value is an integer with a hexadecimal representation.) >> Trying to think about it carefully, I'd expect three things: >> 1. any literals assigned to a variable of type xs:hexadecimal must use the 0x prefix; assigning 0x20 is OK, assigning 32 is an error. >> 2. 'U+' || 0x20 would give U+20 instead of the U+32 it currently gives >> (if I want U+0020 I need to use format-integer to zero-pad, same as decimal integers >> 3. let $test as xs:hexadecimal := 0x20 + 0xA0 return $test would give 0xC0 >> (the $x in "for $x in (0x20 to 0x40) return 'U+' || $x" would be implicitly xs:hexadecimal and return U+20, etc.) >> This is very much a convenience; it's not hard to write a function to produce a hexadecimal representation. But there have been times it would have been a notably welcome convenience, and it's hard to avoid thinking that the language-level version would be more efficient. >> >> thanks! >> Graydon >> >> On Tue, Oct 27, 2026, at 14:35, Christian Grün wrote: >>> Hi Graydon, >>> >>>> I'm wondering if there's an XPath-and-XQuery type in 4.0 for hexadecimal values like U+hhhh format Unicode code points >>>> … >>>> There's xs:hexBinary but that's not the same thing. xs:integer(0x20) gives me 32, which is expected, but I think it tells me 0x20 isn't an integer as such. >>> >>> The query `0x20` results in a single item of type `xs:integer`, so `0x20` and `xs:integer(0x20)` is equivalent. This also means that the following let clauses would inevitably do the same thing: >>> >>> let $test as xs:hexadecimal := 32 >>> let $test as xs:hexadecimal := 0x20 >>> let $test as xs:hexadecimal := xs:integer(0x20) >>> >>> What would you expect `xs:hexadecimal` to be? Do you think of it as a single integer, but one that would be serialized in its hexadecimal representation? >>> >>> Best, >>> Christian >>> >>>
Quoted text · Liam R. E. Quin · 1 line
> Hexadecimal is about how an integer is represented, not how it’s stored.
Absolutely, but just like there are different ways to escape text in XML, being able to use different representations is sometimes useful.
And I'd rather there was a language feature to provide the hex representation; that'll be better-specified and get more testing than anything I am likely to write as a part of some entity file management query. (Fortunately format-integer has got better. :)
Thanks!
Quoted text · Liam R. E. Quin · 39 lines
On Tue, Oct 27, 2026, at 23:34, Liam R. E. Quin wrote: > On Tue, 27 Oct 2026 21:07:27 -0400 > Graydon Saunders via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> > wrote: > > > Trying to think about it carefully, I'd expect three > > things: 1. any literals assigned to a variable of type xs:hexadecimal > > must use the 0x prefix; assigning 0x20 is OK, assigning 32 is an > > error. > > For XSD this could be a facet, but i think it’d have to be on a string > type, alas. > > You are also wanting hex constants, which seems not unreasonable, > since XPath 4 has them already :) > > But i would expect to be able to write > let $amt as xs:integer := 0xff * 3 > return printf("%x", $amt) > > (for example). > > Hexadecimal is about how an integer is represented, not how it’s stored. > > (lets not think about hexadecimal floats!) > > > > > https://qt4cg.org/specifications/xquery-40/xpath-40.html#doc-xpath40-NumericLiteral-HexIntegerLiteral > > > > -- > Liam Quin: Delightful Computing - Training and Consultancy in > XSLT / XML Markup / Typography / CSS / Accessibility / and more... > Outreach for the GNU Image Manipulation Program > Vintage art digital files - fromoldbooks.org >
Written for BaseX 12.4. BaseX may have changed since: please check the current documentation.