A common programming utility for combining several boolean “flags” (each a power of two) into a single integer, and reading them back out.
How it works
Combining flags uses a bitwise OR across the selected power-of-two values; decoding checks which power-of-two values are present in the entered combined number using a bitwise AND.
What this does not include
This does not include non-power-of-two flag systems — standard bitmasks require each flag to be a distinct power of two so they never overlap in bits.
How to use this calculator
- Choose a direction, then enter either the flags to combine or a value to decode.
Frequently asked questions
Why must each flag be a power of two?
Because powers of two each occupy a single, distinct bit position in binary — combining them with addition or OR never causes two different flags to collide into an ambiguous combined value.
Where is this pattern commonly used?
Permission systems (read/write/execute), CSS or configuration option flags, and low-level API settings that pack multiple boolean options into one integer.
What happens if I enter a non-power-of-two flag?
It’s still added, but may not decode cleanly back into a single distinct flag if it overlaps in bits with another value already in the set.