more xpath functions: bitwise operations

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>

Mike, Have you looked at the EXPath:Binary module? Look at expath.org, I think (composing email offline at the moment). It supports several bit-wise manipulations on base64Binary types. DFDL uses hexBinary, but XPath allows a cast between the two types. FYI, Jonathan Cranford
-----Original Message----- From: dfdl-wg-bounces@ogf.org [mailto:dfdl-wg-bounces@ogf.org] On Behalf Of Mike Beckerle Sent: Tuesday, July 29, 2014 8:10 AM To: dfdl-wg@ogf.org Subject: [DFDL-WG] more xpath functions: bitwise operations
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>
participants (2)
-
Cranford, Jonathan W.
-
Mike Beckerle