ForHosting KIT · Developer Utilities

Test bit at position calculator

42 is 101010 in binary, so the bit at position 3, worth 8, is set: enter a whole number and a position counted from 0 on the right to get a yes-or-no answer and the value of that single bit. 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
42
Position
3
You get
Bit value
8

The test bit at position calculator checks one precise place in a non-negative integer's binary representation. Enter an integer and a zero-based position, counting from the least significant bit at position 0.

Choose the integer and count from the right

Start with the non-negative integer you want to inspect and identify the bit position that matters. Positions are zero-based: the rightmost, least significant bit is position 0, the next is position 1, then position 2, and so on. Each position represents a power of two.

Position 0 represents 1, position 1 represents 2, position 2 represents 4, and position 3 represents 8. For example, decimal 42 is binary 101010. Testing position 3 examines the place worth 8, which is set in that number.

This convention is standard in programming, but the zero-based count is an easy source of off-by-one mistakes, so confirm that you are counting from the right and beginning at zero. The calculator accepts non-negative safe integers and positions from 0 through 52.

A yes-or-no answer plus the bit's value

The output provides two complementary answers. Suppose the input value is 42 and the position is 3. Returning both forms avoids repeated work in callers.

The original value and requested position are echoed as well, making logs and batch results easier to audit. No signed-width convention is assumed: inputs are explicitly non-negative, so the result does not depend on whether another language treats a negative integer as 8, 32, 64, or infinitely many two's-complement bits.

Use exact arithmetic for flags and masks

Bit tests appear wherever one integer stores several independent on-or-off states. A permissions field may dedicate one bit to reading, another to writing, and another to administration. A device register can pack readiness, error, and operating-mode flags into a single value.

File formats and network protocols often define fields the same way. Use this calculator when you know the documented position and need a clear, reproducible answer for one flag. Internally, the algorithm divides by the selected power of two, discards lower positions, and checks whether the remaining value is odd.

This avoids JavaScript's ordinary bitwise operators, which coerce numbers to signed 32-bit integers and would produce misleading results above position 31. The calculation is deterministic, uses no network, and performs no conversion through an imprecise binary string. Validate the position against the specification you are implementing, and remember that specifications sometimes number bits from the most significant end or use one-based labels.

Convert such numbering to the zero-based, least-significant convention before calling the capability.

Inspect permission flags

Check whether one documented permission is enabled inside an integer mask and retain its isolated numeric value.

Decode device registers

Read an individual status or error flag from a packed register value without applying 32-bit signed coercion.

Verify protocol fields

Test a specific flag position while debugging encoded headers, file metadata, or serialized application state.

Is position zero the leftmost or rightmost bit?

Position 0 is the rightmost, least significant bit. It represents the value 1.

Why are negative integers rejected?

Negative bit patterns depend on an assumed signed width. Restricting input to non-negative integers makes the result unambiguous across languages and clients.

Why is the maximum position 52?

Position 52 is the highest isolated power of two that remains exact.

How do I check whether bit 3 is set in 42?

Enter 42 and position 3. In binary 42 is 101010, and the place worth 8 holds a one, so the answer is yes and the isolated value is 8. Position 2 of the same number would give no and 0.

What if my specification numbers bits from the left or starts at 1?

Convert the numbering first. This calculator counts from zero at the rightmost, least significant bit, so a one-based label has to be reduced by one and a count from the left has to be turned around.

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/test-bit

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/test-bit \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":42,"position":3}'
{
  "value": 42,
  "position": 3
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.test_bit",
  "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.

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.

The result tells you whether that bit is set with a true or false value and also returns the isolated bit value: the corresponding power of two when set, or zero when clear. This is useful for reading flags, masks, permissions, packed fields, and low-level protocol values without manually converting the entire number to binary.

Choose the integer and count from the right

These boundaries keep every accepted input and every returned isolated bit value exact in JavaScript and JSON clients, rather than silently rounding a large number.

Read the Boolean and isolated value together

The is_set field is true when the selected position contains a one and false when it contains a zero. The bit_value field isolates the same result numerically: it is the power of two represented by that position when the bit is set, or 0 when the bit is clear. Because the 8 place is present, is_set is true and bit_value is 8. If you test position 2 instead, is_set is false and bit_value is 0. A condition can branch directly on the Boolean, while arithmetic or mask-building code can use the isolated value.

What does bit_value mean?

It is the selected power of two when the bit is set, or 0 when the bit is clear.

How much does an API request cost?

Each API request costs $0.002. The calculation is also suitable for the free browser runner.

Read the full KIT documentation →