W3C home > Mailing lists > Public > public-expath@w3.org > March 2013

Bitwise operations (Re: Comments on binary specification)

From: Jirka Kosek <jirka@kosek.cz>
Date: Thu, 14 Mar 2013 10:57:55 +0100
Message-ID: <51419F23.10207@kosek.cz>
To: Michael Kay <mike@saxonica.com>
CC: public-expath@w3.org
> - As binary operators (and, or, not, xor) are pretty low-level,
> wouldn’t it make sense to restrict them to single octets (i.e., items
> of type xs:integer)? Otherwise, the operation $a ^ $b would need to be
> written as bin:binary-to-octets(bin:binary-xor(bin:octets-to-binary($a),
> bin:octets-to-binary($b)))). What about binary:xor($a, $b)? 

> Yes, I think it's a separate discussion whether bitwise operators on integers would be more useful. I think the main problem is that we don't have hex literals, so we can't say $x & xFF00, instead we have to say either
> 
> (1) if we use hexBinary: bin:and($x, xs:hexBinary("FF00"))
> (2) if we use base64Binary: bin:and ($x, xs:base64Binary("/wA="))
> (3) if we use integer: bin:and($x, 65280) 

I think that it is pretty easy to find scenarios where (1) and (2) is
more handy and scenarios where (3) is more handy. If you read some
external binary file and checking some flags inside it it would be more
natural to use (1)/(2) so you don't have to call binary-to-octets().
OTOH if you do a lot of binary calculation on data coming from your
query then (3) is more natural.

Personally I'm little bit more in favour of (1)/(2) then of (3).
Probably we need more real-world use cases here.

> None of these is nice, but the first seems to me the most readable. If we go with (and/or/not) working on integers, then perhaps we should also have functions
> 
> bin:hex("FF00") => 65280
> 
> bin:octal("177400") => 65280 (since you're telling me that there are indeed people who still use octal...) 

We can even add bin:binary("1111111100000000") to make bitmasking
easier. I think that we should have these functions available even if
bitwise functions will operate on xs:hexBinary/xs:base64Binary (maybe
without bin:hex() which would became bin:hexBinary() alias then).

-- 
------------------------------------------------------------------
  Jirka Kosek      e-mail: jirka@kosek.cz      http://xmlguru.cz
------------------------------------------------------------------
       Professional XML consulting and training services
  DocBook customization, custom XSLT/XSL-FO document processing
------------------------------------------------------------------
 OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 rep.
------------------------------------------------------------------
    Bringing you XML Prague conference    http://xmlprague.cz
------------------------------------------------------------------


Received on Thursday, 14 March 2013 09:58:25 GMT

This archive was generated by hypermail 2.3.1 : Thursday, 14 March 2013 09:58:26 GMT