ForHosting KIT · Developer Utilities

Bitmask flags decoder

With read (1), write (2), execute (4) and admin (8), the value 13 decodes to read, execute and admin, with nothing left unexplained. Enter a stored number and your own list of named bits to see which permissions or options are on. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Value
13
You get
Active flags
read, execute, admin
Unknown bits
0

The bitmask flags decoder turns a compact integer into the permission, feature, status, or option names it represents. Provide the stored value and a list that maps each name to a power-of-two bit. The result preserves your declaration order, returns every active name, and reports any value left over from bits you did not define.

How a single number stores several options

A bitmask packs many yes-or-no settings into one integer. Each option owns one binary position worth a power of two: 1, 2, 4, 8, 16 and so on. Because those positions never overlap, adding the values of the options that are on gives a unique total, and that total can be taken apart again. The decoder checks every name in your list to see whether its position is present in the stored value. 13, for instance, is 8 plus 4 plus 1, so with read as 1, execute as 4 and admin as 8 those three come back as active, in the order you declared them. A value of zero is valid and simply means no option is on.

What the leftover tells you, and common slips

Whatever part of the number your list does not explain is reported separately instead of being dropped. A leftover of zero means your definitions cover the whole value; anything else often points to a flag added on the server, an internal option you left out on purpose or lists from two different versions. Typical mistakes are giving a flag a value that is not a power of two, such as 3, or reusing the same bit for two names; both are refused with a clear message instead of producing a plausible but wrong list. Names are trimmed and must be unique.

Describe the mask with explicit named bits

Start with the non-negative integer in the value field, then add one flags row for every meaning your system defines. Each row contains a name and a bit. The bit must be a positive power of two: 1, 2, 4, 8, 16, and so on.

Those values represent independent binary positions, which makes them safe to combine by addition or bitwise OR. Names are trimmed and must remain unique, and bit values must also be unique, because two labels for the same position would make the decoded answer ambiguous. Inputs use JavaScript-safe non-negative integers, supporting exact values through 9,007,199,254,740,991 and individual declared bits through 4,503,599,627,370,496.

Invalid records fail clearly instead of being silently coerced into a plausible but incorrect permission list.

Explain access-control fields

Turn a stored permission mask into readable names before showing it in an admin interface or audit export.

Migrate legacy configuration

Expand compact numeric settings into explicit booleans or labels during a database or application migration.

What values can I decode?

Any non-negative JavaScript-safe integer. Each declared flag bit must be a unique positive power of two.

Can flag names contain spaces?

Yes. Names are strings and surrounding whitespace is trimmed. Empty names and duplicate trimmed names are rejected.

Why must each flag be a power of two?

Because each power of two, 1, 2, 4, 8, 16 and so on, is its own binary position, so flags can be added together without overlapping. For the same reason every bit and every name must be unique, or the decoded answer would be ambiguous.

What does a leftover value mean?

It is the part of the number your list does not explain. Decoding 13 with only read (1), write (2) and execute (4) leaves 8 over. That often signals a new flag, an internal option you left out on purpose or a version mismatch.

Does the order of my flag list matter?

Only for display. Definitions can go in any order, and the active names come back in the order you declared them, so your interface keeps its preferred order instead of a numeric sort.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/bitmask-flags-decode

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/bitmask-flags-decode \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":13,"flags":[{"name":"read","bit":1},{"name":"write","bit":2},{"name":"execute","bit":4},{"name":"admin","bit":8}]}'
{
  "value": 13,
  "flags": [
    {
      "name": "read",
      "bit": 1
    },
    {
      "name": "write",
      "bit": 2
    },
    {
      "name": "execute",
      "bit": 4
    },
    {
      "name": "admin",
      "bit": 8
    }
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.bitmask_flags_decode",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_flags256
max_safe_integer9007199254740991
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

It is useful when reading database fields, API payloads, protocol values, access-control settings, and legacy configuration without manually converting numbers to binary or relying on language-specific bitwise behavior.

Describe the mask with explicit named bits

Definitions may appear in any order; active_flags follows the order you supplied, which lets an application keep a preferred display order instead of receiving an arbitrary numeric sort. The decoder accepts zero as a valid mask and returns an empty active_flags array for it.

Understand active flags and unknown bits

For every declaration, the decoder tests whether that binary position is present in value. Keeping that remainder visible is safer than dropping information. The original value is returned unchanged so logs and downstream checks can retain exact provenance. If it is present, the corresponding name is appended to active_flags and its numeric bit contributes to the declared active total. The response also includes unknown_bits, calculated as the original value minus all active bits that were declared. A zero unknown_bits value means the supplied definitions fully explain the mask. A nonzero value is not automatically an error: it often signals a newly introduced server flag, an intentionally omitted internal option, or a schema version mismatch. For example, if value is 13 and the declared bits are read=1, write=2, execute=4, and admin=8, the active names are read, execute, and admin, while unknown_bits is zero. If bit 8 were omitted from the definitions, the same input would return read and execute with unknown_bits equal to 8.

Use deterministic decoding in permission and option workflows

Bitmasks are common in database columns, operating-system modes, feature switches, device registers, game state, and third-party API responses because many booleans fit into one integer. This capability makes those fields readable at an integration boundary. Store the flag definitions beside the schema version, call the decoder when a record enters your pipeline, and use active_flags for display, filtering, or policy checks. Monitor unknown_bits as a compatibility signal: a nonzero remainder can route the record for review before software mistakes a new permission for an ordinary old value. The algorithm performs bounded arithmetic over at most 256 definitions and uses no network, clock, locale, random source, or mutable state, so identical JSON always produces identical JSON. It also avoids JavaScript's signed 32-bit bitwise operators and therefore handles exact masks well above 32 bits within the safe-integer range. Interactive decoding is free, while successful automated API tasks use the published base price of $0.002.

Inspect API and protocol options

Decode combined option values from an integration while retaining undeclared bits as a schema-drift warning.

What does unknown_bits mean?

It is the portion of value that is set but not represented by any supplied flag definition. Zero means the declarations explain the entire mask.

Does the result preserve flag order?

Yes. active_flags follows the order of the supplied definitions, regardless of their numeric bit order.

How much does the API cost?

Each successful API task uses the published base price of $0.002. You can also run the decoder free in the browser.

Read the full KIT documentation →