Binary converter
42 in binary is 101010, and 101010 turns back into 42: one converter for whole numbers in both directions, with the bit count and a visible minus sign for negatives. Handy for homework, bit masks and permission flags. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Value
- 42
- Direction
- To binary
- Result
- 101010
- Decimal
- 42
- Binary
- 101010
- Bits
- 6
A binary converter rewrites a whole number between everyday base ten and base two so you can read the same integer as a decimal or as a string of bits. 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 and binary integers convert both ways
Start with a finite integer written in ordinary base ten. If the value is zero, the binary representation is the single digit zero and you are done. If the value 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. Going the other way uses Horner's method: start at zero and, for each bit from left to right, double the running total and add the bit.
Equivalently, each bit position k from the right corresponds to two to the power k, and the bit is one when that power appears in the unique sum that rebuilds the integer. Forty-two, for example, is thirty-two plus eight plus two, which is the six-bit string 101010; feeding 101010 back through Horner recovers forty-two. 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 for a binary integer converter stays clear and trustworthy.
Where a binary integer converter shows 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, the decimal 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 1101 is clearer than thirteen when explaining which flags are set, and the reverse direction checks that a handwritten bit pattern still equals the decimal in the spec.
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 and the inverse; 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.
Keep requests inside the safe-integer limit, pin the string result in tests, and you get reproducible conversions for homework, LMS plugins, and edge workers without standing up a computer-algebra system of your own.
What you can do with it
Homework and place-value drills
Check textbook answers for converting whole numbers to base two and back, including zero and negatives with a clear leading minus.
Bit masks and flag documentation
Turn decimal flag values into readable bit strings, or recover the decimal from a handwritten pattern, when writing protocol notes and register maps.
FAQ
How do I convert binary back to decimal?
The result field is the decimal integer as a string, for example 101010 becomes 42.
What does the binary converter cost?
The browser tool is free and runs locally.
How do I convert 42 to binary by hand?
Divide by two again and again and write down each remainder: 42 gives 0, 1, 0, 1, 0, 1. Read the remainders from last to first and you get 101010, the same result the converter shows.
How are negative numbers shown in binary?
With a minus sign in front of the bits, so the sign is always obvious. The converter does not pick a fixed bit width, so you never get an ambiguous two's complement pattern that depends on the system.
Can I convert a number with decimals, such as 3.5?
No. Only whole numbers are accepted, and 3.5 is refused with a clear message instead of a silent wrong answer. Binary fractions would need a binary point, which this converter deliberately leaves out.
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/conv/binary \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"value":"42","direction":"to_binary"}'const res = await fetch("https://api.kit.forhosting.com/conv/binary", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"value": "42",
"direction": "to_binary"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/conv/binary",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"value": "42",
"direction": "to_binary"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/conv/binary", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"value":"42","direction":"to_binary"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"value":"42","direction":"to_binary"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/conv/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
{
"value": "42",
"direction": "to_binary"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "conv.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
Type forty-two with direction to_binary and you receive the bit string 101010; send that bit string back with direction from_binary and you recover forty-two as a decimal string. Pricing for successful API calls is the published base of $0.002 per item.
How decimal and binary integers convert both ways
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, which direction to pick, and what comes back
Send a required field value holding the integer to convert and a required field direction that chooses the mapping. 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. 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-and-binary page. Direction to_binary (aliases decimal_to_binary, encode) treats value as a decimal whole number and returns the base-two string. Direction from_binary (aliases binary_to_decimal, decode) treats value as a binary integer of digits zero and one, with an optional 0b prefix, and returns the decimal integer as a string. Value may arrive as a JSON integer or as a digit string with an optional leading plus or minus sign; aliases n, number, input, text, decimal, and binary are accepted so forms and scripts can use the name that fits their UI. Missing value, missing direction, 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 a cleaned value string, the canonical direction, the converted result as a string, both decimal and binary views, the count of unsigned bits, a boolean negative flag, and the from and to bases. Examples include value forty-two with to_binary mapping to result 101010, and value 101010 with from_binary mapping back to result 42. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where a binary integer converter shows 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 and decimal strings for coding exercises and golden tests covering powers of two and edge cases.
Technical questions
What inputs does the binary converter accept?
A required integer field value (aliases: n, number, input, text, decimal, binary) and a required direction of to_binary or from_binary. Value must be a whole number—JSON integer or digit string with optional +/−. Fractions and non-numeric text are rejected.
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 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.