Test bit at position calculator
The test bit at position calculator checks one precise place in a non-negative integer's binary representation.
Run — free
Enter an integer and a zero-based position, counting from the least significant bit at position 0. 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
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. 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 output provides two complementary answers. 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. Suppose the input value is 42 and the position is 3. 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. Returning both forms avoids repeated work in callers. A condition can branch directly on the Boolean, while arithmetic or mask-building code can use the isolated value. 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.
What you can do with it
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.
FAQ
Is position zero the leftmost or rightmost bit?
Position 0 is the rightmost, least significant bit. It represents the value 1.
What does bit_value mean?
It is the selected power of two when the bit is set, or 0 when the bit is clear.
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?
JavaScript and JSON represent integers exactly only through the safe-integer range. Position 52 is the highest isolated power of two that remains exact.
How much does an API request cost?
Each API request costs $0.002. The calculation is also suitable for the free browser runner.
For developers — API access
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.
API endpoint
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.
Call it from your stack
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}'const res = await fetch("https://api.kit.forhosting.com/dev/test-bit", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"value": 42,
"position": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/test-bit",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"value": 42,
"position": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/test-bit", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"value":42,"position":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"value":42,"position":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/test-bit", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"value": 42,
"position": 3
}Example response
{
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |