Decimal to binary converter
42 in binary is 101010, six bits long: enter any whole number and get its binary digits for homework, bit masks or permission flags. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Decimal whole number
- 42
- Binary
- 101010
- Bits
- 6
- Base
- 2
A decimal to binary converter rewrites a whole number from base ten into base two so every place value is a power of two instead of a power of ten. You type an integer such as forty-two and receive the bit string one zero one zero one zero, which means thirty-two plus eight plus two. Students use the tool to check homework on place value and repeated division by two; developers use it when documenting bit masks, protocol flags, or permission bits that are easier to reason about in binary than in decimal. Negative integers keep a leading minus in front of the unsigned bit pattern so the sign is obvious without inventing a fixed bit width. Non-integers, bare text, NaN, and Infinity fail with a clear validation error instead of a silent wrong answer.
How decimal to binary conversion works
Start with a finite integer n written in ordinary base ten. If n is zero, the binary representation is the single digit zero and you are done. If n is negative, remember the sign, work with the absolute value, and reattach a leading minus to the final bit string so readers see sign-magnitude form rather than an ambiguous two’s-complement word of unknown width.
For a positive absolute value, divide by two repeatedly and record each remainder: the remainder is the next least-significant bit, so you collect remainders from right to left until the quotient becomes zero. Reading those remainders in reverse order produces the standard left-to-right binary string without leading zeros except for the number zero itself. Equivalently, each bit position k from the left corresponds to a power of two, and the bit is one when that power appears in the unique sum that rebuilds n.
Values must stay inside JavaScript’s safe integer range so every digit remains exact when the result is serialized. Fractional input such as three point five is rejected because binary place values for non-integers would require a radix point and a different teaching contract; this capability is deliberately limited to whole numbers so the search intent “decimal to binary converter” for integers stays clear and trustworthy.
Where decimal to binary tools show up in real work
Secondary-school math courses introduce base conversion with repeated division by two and place-value charts; a trusted oracle that returns the bit string and the bit count speeds answer keys and classroom demos without spreadsheet formulas. Computer science labs teach bit masks, permission flags, and status words where writing one one zero one is clearer than thirteen when explaining which flags are set. Embedded firmware notes and protocol documentation often list register fields in binary next to their decimal addresses so reviewers can verify bit offsets at a glance.
Coding-interview warm-ups and online judges ask candidates to implement decimal-to-binary conversion; tutors compare student output against a known-good string for zero, powers of two, and negative edge cases. Treat two’s-complement fixed-width packing, floating-point binary fractions, and multi-base radix tables as separate search intents with their own landings rather than stretching this whole-number converter past its honest scope.
What you can do with it
Homework and place-value drills
Check textbook answers for converting whole numbers to base two, including zero and negatives with a clear leading minus.
Bit masks and flag documentation
Turn decimal flag values into readable bit strings when writing protocol notes, permission tables, or register maps.
FAQ
How are negative numbers shown in binary?
As sign-magnitude text: a leading minus followed by the binary of the absolute value (for example −10 → −1010). Fixed-width two’s complement is a different contract.
What does it cost?
The browser tool is free and runs locally.
What is 42 in binary?
42 is 101010 in binary, six bits long. The ones sit in the places worth thirty-two, eight and two, and those three values add up to forty-two.
How do I convert a decimal number to binary by hand?
Divide by two again and again and write down each remainder. Reading the remainders from last to first gives the binary digits, so 42 becomes 101010.
Can I convert a number with a decimal point?
No. Only whole numbers are accepted, so a value such as three point five is rejected instead of being rounded. That keeps every result an exact binary whole number.
Related tools
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/fmt/decimal-binary \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":42}'const res = await fetch("https://api.kit.forhosting.com/fmt/decimal-binary", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 42
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/fmt/decimal-binary",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 42
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/fmt/decimal-binary", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":42}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":42}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/fmt/decimal-binary", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 42
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "fmt.decimal_binary",
"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.
Limits
max_abs | 9007199254740991 |
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. |
Technical notes
Pricing for successful API calls is the published base of $0.002 per item.
How decimal to binary conversion works
The algorithm is pure integer arithmetic: no floating-point rounding, no random seeds, no wall-clock timestamps, and no network calls, so identical inputs always produce identical JSON.
What you send and what you get back
Send a single required field n holding a decimal whole number. Absolute values larger than nine quadrillion and a bit—Number.MAX_SAFE_INTEGER—are rejected so the binary string cannot silently lose low-order bits. Examples include n equals zero mapping to binary zero with one bit, n equals forty-two mapping to one zero one zero one zero with six bits, and n equals negative ten mapping to minus one zero one zero with four bits in the digit part. If you need arbitrary source and target bases from two through thirty-six in one call, use a general radix converter landing rather than overloading this decimal-only page. Aliases number, value, decimal, and input are accepted so forms and scripts can use the name that fits their UI. n may be a JSON integer or a string of digits with an optional leading plus or minus sign. Missing n, empty strings, decimals with a fractional part, scientific notation, bare words, NaN, and Infinity fail with invalid_input and are not charged. On success the response echoes the cleaned integer n, the binary string under binary, the count of unsigned bits under bits, a boolean negative flag, and base set to two for explicitness in multi-tool pipelines. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where decimal to binary tools show up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Interview and unit-test fixtures
Generate expected binary strings for coding exercises and golden tests covering powers of two and edge cases.
Technical questions
What inputs does the decimal to binary converter accept?
A single integer field n (aliases: number, value, decimal, input). It must be a whole number—JSON integer or digit string with optional +/−. Fractions and non-numeric text are rejected.
What happens if I enter a decimal fraction?
The request fails with invalid_input. This tool converts whole numbers only; fractional binary would need a radix point and a separate product intent.
Is there a size limit?
Yes. The absolute value of n must not exceed Number.MAX_SAFE_INTEGER (9007199254740991) so every bit stays exact in JavaScript JSON.