<div dir="ltr"><div dir="ltr"><div>Hugh,</div><div><br></div><div>My read of this discussion [1] is that bitwise operators are not supported and we would need to add them as a GDAL extension. This is pretty easy to do: see [2]. Alternatively, bitwise operators are probably supported by the ExprTk expression parser [3] (supported by GDAL) or this pull request [4].</div><div><br></div><div>Dan</div><div><br></div><div>[1] <a href="https://github.com/beltoforion/muparser/discussions/154#discussioncomment-13104418">https://github.com/beltoforion/muparser/discussions/154#discussioncomment-13104418</a></div><div>[2] <a href="https://github.com/OSGeo/gdal/pull/13187/files">https://github.com/OSGeo/gdal/pull/13187/files</a></div><div>[3] <a href="https://www.partow.net/programming/exprtk/">https://www.partow.net/programming/exprtk/</a> </div></div>[4] <a href="https://github.com/OSGeo/gdal/pull/13470">https://github.com/OSGeo/gdal/pull/13470</a></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Dec 3, 2025 at 2:58 PM Hugh Graham via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi, <br><br>I am using VRT muparser expressions for bitwise operations when creating masks and wanted to understand why I can't get the <i>bitwise & </i>operator working? My current solution is to use fmod which is fine (and I think equivalent) but using "&" would be convenient and a bit easier to read...<br><br>To illustrate, the following file works: <br><a href="https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-fmodmask-vrt" target="_blank">https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-fmodmask-vrt</a> <br>the expression used here is:"(fmod(Fmask, 16) >= 8) || (fmod(Fmask, 8) >= 4) ? 0 : 1"<br><br>```<br>gdal convert "/vsicurl/<a href="https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-fmodmask.vrt" target="_blank">https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-fmodmask.vrt</a>" "test.tif"<br>```<br><br>However, the following file fails: <br><a href="https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-bitmask-vrt" target="_blank">https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-bitmask-vrt</a><br>the expression parsed as: "((Fmask & 8) > 0 || (Fmask & 4) > 0) ? 0 : 1" in the XML but provided as (to my xml parser):<br><br>"((Fmask & 8) > 0 || (Fmask & 4) > 0) ? 0 : 1"<br><div><br></div><div>```</div><div>gdal convert "/vsicurl/<a href="https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-bitmask.vrt" target="_blank">https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-bitmask.vrt</a>" "test.tif"<br>0...10...20..ERROR 1: Unexpected token "& 8) > 0 || (Fmask & 4) > 0) ? 0 : 1 " found at position 8.</div><div>``` <br><br>So, is using "&" possible, or should I just stick with fmod and not worry about it?<br><br>Any help would be much appreciated. <br><br>Hugh<br><br><br><br><br><br><br></div></div>
</div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div>