Repository: construct/construct

Issue:
Bitwise And is compiled as logical And
`ExprMixin` for bitwise has different behavior when compiled.

The following test is sufficient to catch the problem
```python
def test_compile_binexpr_bitwise_and():
    d = Struct(
        "a" / Int8ub,
        "cond" / If(this.a & 32, Int8ub),
        Terminated,
    )
    common(d, b"\x00", {"a": 0, "cond": None})
    common(d, b"\x01", {"a": 1, "cond": None})
    common(d, b" \x05", {"a": 32, "cond": 5})
```

Discussion:

Patch:
diff --git a/construct/expr.py b/construct/expr.py
index 00a63f2..c1dd179 100644
--- a/construct/expr.py
+++ b/construct/expr.py
@@ -14,8 +14,8 @@ opnames = {
     operator.xor : "^",
     operator.lshift : "<<",
     operator.rshift : ">>",
-    operator.and_ : "and",
-    operator.or_ : "or",
+    operator.and_ : "&",
+    operator.or_ : "|",
     operator.not_ : "not",
     operator.neg : "-",
     operator.pos : "+",


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index 1876796..e92426c 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2398,3 +2398,13 @@ def test_nullterminated_longterm_issue_1046():
     d = NullTerminated(GreedyBytes, term=b"END")
     assert d.parse(b"xxxEND") == b"xxx"
     raises(d.parse, b"xENDxx") == StreamError
+
+def test_compile_binexpr_bitwise_and_issue_1039():
+    d = Struct(
+        "a" / Int8ub,
+        "cond" / If(this.a & 32, Int8ub),
+        Terminated,
+    )
+    common(d, b"\x00", {"a": 0, "cond": None})
+    common(d, b"\x01", {"a": 1, "cond": None})
+    common(d, b" \x05", {"a": 32, "cond": 5})