bitflag
A bitflag is a representation technique in computing that uses individual bits within a binary value to represent multiple boolean options. Each flag corresponds to a specific bit position; when the bit is 1, the flag is enabled, and when it is 0, the flag is disabled. Flags are typically defined as powers of two (1, 2, 4, 8, 16, …), allowing a collection of flags to fit in a single integer or a bitset.
Operations on bitflags are performed with bitwise operators. To combine flags, a bitwise OR is used. To
Common usage areas include permission systems (read, write, execute), configuration options, feature toggles, protocol capabilities, and
Example: define READ = 1, WRITE = 2, EXECUTE = 4. A permissions value of READ | WRITE means read
Advantages include compact memory usage, fast bitwise operations, and straightforward testing of flag subsets. Pitfalls involve