How to convert an 8-bit integer into a binary string in xquery?

Posted by philcolbourn on Stack Overflow See other posts from Stack Overflow or by philcolbourn
Published on 2010-04-21T10:19:51Z Indexed on 2010/04/21 10:23 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

At work today, we threw together this attempt:

xquery version "1.0";
declare option saxon:output             "omit-xml-declaration=yes";
declare variable $x := 99;

string-join(
    for $b in (128,64,32,16,8,4,2,1)
    let $xm := $x mod ($b*2)
    return
        if ( $xm >= $b ) then "1" else "0"
, "")

Do you have a better way?

© Stack Overflow or respective owner

Related posts about xquery

Related posts about integer