TurantToolsdev</> All tools

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.

FlagValueBinary
READ100001
WRITE200010
DELETE400100
SHARE801000
ADMIN1610000

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.
Binary, Hex, Decimal & Octal ConverterSee any number in binary and hex.

More articles