ForHosting KIT · Developer Utilities

Bitmask flags decoder

The bitmask flags decoder turns a compact integer into the permission, feature, status, or option names it represents.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

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. 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

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. 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. 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.

Understand active flags and unknown bits

For every declaration, the decoder tests whether that binary position is present in value. 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. Keeping that remainder visible is safer than dropping information. 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. The original value is returned unchanged so logs and downstream checks can retain exact provenance.

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. The browser runner and API share this same library. Interactive decoding is free, while successful automated API tasks use the published base price of $0.002.

Explain access-control fields

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

Inspect API and protocol options

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

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.

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.

Can flag names contain spaces?

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

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.

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.

Read the full KIT documentation →