concept

Enum Flags

Enum flags are a programming pattern that uses bitwise operations to combine multiple values from an enumeration into a single variable, allowing efficient storage and manipulation of sets of options or states. This is typically implemented by assigning powers of two (e.g., 1, 2, 4, 8) to enum members, enabling the use of bitwise OR to combine them and bitwise AND to test for presence. It is commonly used in languages like C#, Java, and C++ to represent combinations of flags or permissions in a compact and performant way.

Also known as: Bit Flags, Flag Enums, Bitmask Enums, Flags Enumeration, Bitwise Enums
🧊Why learn Enum Flags?

Developers should use enum flags when they need to represent multiple, non-exclusive options or states that can be combined, such as file permissions (read, write, execute), user roles, or configuration settings, as it reduces memory usage and improves performance compared to using separate boolean variables or collections. This pattern is particularly useful in systems programming, game development, or any scenario where bit-level efficiency is critical, such as network protocols or low-level APIs.

Compare Enum Flags

Learning Resources

Related Tools

Alternatives to Enum Flags