[DFDL-WG] more xpath functions: bitwise operations

Mike Beckerle mbeckerle.dfdl at gmail.com
Tue Jul 29 10:09:59 EDT 2014


There seems to be no reasonable way to deal with binary data in our XPath
subset.

Ex: This formula, for unsigned binary integer n: (C-programming language)

 (n >> 1) ^ (-(n & 1))

This is the decoder expression for what are called "zig zag integers" which
is a way of encoding signed integers into unsigned integers so that there
is no sign-bit that must be extended to the full length. (A trick used in
Google Protocol Buffers - an increasingly popular format). There is no
reason DFDL cannot encode and decode these zig-zag integers, except that
there is no bit-wise arithmetic to do the calculation on inputValueCalc and
outputValueCalc.


The shift right isn't hard, and the & 1 becomes a simple enough
if-then-else and a division. But there is no reasonable way to do a bitwise
XOR (The ^ operator).

I suspect we need a library of bitwise operations that interpret their
arguments as binary integers:

My first cut would be:

arithmetic-shift-right(width, count)
arithmetic-shift-left (width, count)
logical-shift-right(width, count)
logical-shift-left(width, count)
bitwise-and(width, n1, n2)
bitwise-or(width, n1, n2)
bitwise-not(width, n1)
bitwise-xor(width, n1, n2)

Where width is 8, 16, 32, or 64.

The arithmetic shifts and the logical shift left are for symmetry only.
They can easily be implemented by multiplies and divides by 2.

Mike Beckerle | OGF DFDL Workgroup Co-Chair | Tresys Technology |
www.tresys.com
Please note: Contributions to the DFDL Workgroup's email discussions are
subject to the OGF Intellectual Property Policy
<http://www.ogf.org/About/abt_policies.php>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ogf.org/pipermail/dfdl-wg/attachments/20140729/1d2108fd/attachment-0001.html>


More information about the dfdl-wg mailing list