If you want to count the number of required bits, you could something as follows:

declare function local:bits($n as xs:integer) as xs:integer { ($n idiv 2) ! (if (.) then 1 + local:bits(.) else 0) }; local:bits(65535) There are probably various solutions to solve the problem; suggestions are welcome. On Wed, Aug 14, 2019 at 1:07 PM Christian Grün <christian.gr...@gmail.com> wrote: > > Hi Giuseppe, > > > Thanks! I missed that specification. Is there any reason why only the first > > octet is provided? More in general, I was interested to test how many > > bits/octects are used to represent an integer. > > The function was mostly introduced to convert byte sequences to a > binary representation and vice versa. The xs:integer data type because > it’s the predominant numeric type in XQuery (otherwise, the input > would have needed to be cast to xs:byte). > > > > > > > > > > On Aug 14, 2019, at 10:58 AM, Christian Grün <christian.gr...@gmail.com> > > wrote: > > > > bin:length(convert:integers-to-base64(1 to 10000000) > > > >