Bit Flags: Many Options in One Number
Powers of two, OR to combine, AND to check, with a permissions example in binary.
By the TurantTools Dev team · Updated October 27, 2026 · 2 min read
Bit flags store several yes/no options in one integer: each option gets a power of two, and you combine them with OR. It's how Unix permissions, many APIs and game engines store settings compactly.
| Flag | Value | Binary |
|---|---|---|
| READ | 1 | 00001 |
| WRITE | 2 | 00010 |
| DELETE | 4 | 00100 |
| SHARE | 8 | 01000 |
| ADMIN | 16 | 10000 |
A user with READ, WRITE and SHARE
const perms = READ | WRITE | SHARE; // 11, binary 01011 const canShare = (perms & SHARE) !== 0; // true const canDelete = (perms & DELETE) !== 0; // false const withDelete = perms | DELETE; // 15
- In a database, a flags column is compact but hard to query and read; separate booleans or a join table are often clearer.
- JavaScript bitwise operators work on 32 bits; use BigInt for more than 31 flags.