← All examples

Wide bits

Bitwise operators and shifts on integers past 128 bits, at the type's true width: and int128/uint128 shifts and not.bit at all 128 bits.

wide_bits.zg
# Bitwise operators and shifts on integers past 128 bits (owner, 2026-10-03: "Do the bit shit"),
# at the type's true width: and int128/uint128 shifts and `not.bit` at all 128 bits.
MAIN {
    let 'a': not_std.uint256 = 2 pow 200 plus 12345;
    let 'b': not_std.uint256 = (2 pow 255) minus 1;
    std::print.useful[('a' and.bit 'b'), newln];
    std::print.useful[('a' xor 'b'), newln];
    std::print.useful[('a' shl 55), " ", ('a' shr 190), newln];
    let 'n': not_std.int256 = -(2 pow 200);
    std::print.useful[('n' or.bit 7), " ", ('n' shr 3), newln];
    let 'z': not_std.uint256 = 0;
    let 'all': not_std.uint256 = not.bit 'z';
    std::print.useful['all', newln];
    let 'u': uint128 = 1;
    let 'top': uint128 = 'u' shl 127;
    let 'flip': uint128 = not.bit 'u';
    std::print.useful['top', " ", 'flip', newln];
}
Output
1606938044258990275541962092341162602522202993782792835313721
57896044618658096104847448245353678384672899991657679497525798221163729506246
57896044618658097711785492504343953926634992332820282020173567503155675004928 1024
-1606938044258990275541962092341162602522202993782792835301369 -200867255532373784442745261542645325315275374222849104412672
115792089237316195423570985008687907853269984665640564039457584007913129639935
170141183460469231731687303715884105728 340282366920938463463374607431768211454