Guide
Bit flags and bitmasks: combining options in one number
Many systems store several yes-or-no options in a single integer: file permissions, feature toggles, user roles, hardware registers and protocol headers all do it. Each option occupies one bit, so one number can hold up to 32 or 64 independent switches and be checked with a single, very fast operation. This calculator names the bits, combines and decodes values and writes the matching enum for your language.
Why powers of two
Each flag is given a value with exactly one bit set: 1, 2, 4, 8, 16 and so on, written in code as 1 << 0, 1 << 1, 1 << 2. Because no two flags share a bit, any combination adds up to a unique number, and the number can always be taken apart again. Read, Write and Share as 1, 2 and 8 combine to 11, and 11 can only mean those three.
The four operations
Combining flags uses bitwise OR: Read | Write sets both bits. Testing uses AND: (value & Write) != 0 is true when the Write bit is set. Removing a flag uses AND with the inverted flag: value & ~Write clears that bit and leaves the others. Toggling uses XOR: value ^ Write flips it. These operations take a single CPU instruction, which is why flags are popular in performance-sensitive code.
Three views of one value
The decimal value is what usually ends up in a database column or a configuration file. The hexadecimal value lines up with bits in groups of four, so 0xB is the same as binary 1011. The binary view, grouped in fours from the right, shows each flag’s bit directly. You can tick flags, or type a decimal or hex value to decode it, and the other views update.
Decoding stored values
Paste the mysterious number from a database or log and read which named flags it contains. If the value has bits set above the last flag you named, the calculator warns you, which usually means the list of flag names is incomplete or the data came from a newer version of the software.
The generated enums
TypeScript gets an enum with None = 0, each flag as 1 << n and an All member combining every flag. C# gets the [Flags] attribute, which also makes ToString() print the names of combined values. Python gets an IntFlag class with auto() values, Rust a bitflags! block for the bitflags crate, Go a typed constant block using 1 << iota, and C a typedef enum with unsigned shifts.
A worked example
The Sample defines five permission flags: Read, Write, Delete, Share and Admin, as 1, 2, 4, 8 and 16, and sets the value 11. The calculator shows the binary 0 1011, the flags set as Read, Write and Share, and the expression Permission.Read | Permission.Write | Permission.Share. The TypeScript enum contains Share = 1 << 3, and All = Read | Write | Delete | Share | Admin,. Switching to Go writes the same flags as constants starting with Read Permission = 1 << iota.
Pitfalls
Languages differ in integer size and signedness, so the 32nd flag can turn values negative in JavaScript and Java; use unsigned types or 64-bit integers where available. Never reorder or remove flags once values are stored, and document the meaning of each bit next to the enum. For more than a few dozen options, a set of named columns or a list may be clearer than a mask.
Related tools
- Chmod Calculator works with the best-known bitmask of all, Unix permissions.
- Big-O Calculator explains why bit operations count as constant time.
- Protobuf Formatter checks schemas that carry flag fields.
- Hash Generator produces hex digests to compare with bit views.
Checked against the current version of the Bitmask Calculator on .

