Skip to content

mask [terminology]

Terminology

Usage

  • Use for a bitmask applied through bitwise operations.
  • Keep the semantic name rather than replacing it with a single letter.
mask = 0xFFFFFFFF
# ...
a &= mask
b &= mask
while b:
    partial = (a ^ b) & mask # Sum without carry.
    carry = ((a & b) << 1) & mask # Carry, shifted to the next bit.
    a, b = partial, carry

See 371. Sum of Two Integers.