Bitwise Operations
All bitwise operations follow Python’s two’s complement semantics for negative numbers.
| Operator | Description |
|---|---|
a & b | Bitwise AND |
a | b | Bitwise OR |
a ^ b | Bitwise XOR |
~a | Bitwise NOT: $~x = -(x + 1)$ |
Each accepts both BInt and Int as the right operand. In-place variants
(&=, |=, ^=) are also available.
var a = BInt(0b1100)
var b = BInt(0b1010)
print(a & b) # 8 (0b1000)
print(a | b) # 14 (0b1110)
print(a ^ b) # 6 (0b0110)
print(~a) # -13
# Negative numbers use two's complement:
print(BInt(-1) & BInt(255)) # 255