Bitmasks
Bitmasks are values used to encode multiple Boolean flags within a single binary quantity, typically an integer. Each bit position in the mask represents a separate condition or option, which allows compact storage and fast manipulation of large sets of binary states.
Common operations rely on bitwise operators. To turn on a flag, you OR the value with a
Mask creation and composition: a single-bit mask is produced by shifting 1 left by k positions, such
Common applications: storing configuration flags, feature toggles, permissions, file modes, and protocol fields. They enable fast
Notes: be mindful of integer width and sign in different languages; bit shifts may have different semantics;