Decimal to fixed-point converter
Turn a decimal into the integer stored in a Q.n fixed-point format: 0.1 with 8 fractional bits stores 26, which really stands for 0.1015625, an error of 0.0015625. Made for firmware, DSP and FPGA work. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Value
- 0.1
- Fractional bits
- 8
- Rounding
- Nearest
- Q format
- Q.8
- Scale
- 256
- Resolution
- 0.00390625
Engineers converting a design constant, a filter coefficient, or a sensor reading need the stored integer, the reconstruction error after rounding, and the resolution two-to-the-minus-n — not a floating-point hex dump. This decimal to fixed-point converter accepts a real decimal value and a fractional-bit count n, multiplies by two to the n, snaps onto an integer with a documented rounding mode, and returns the stored code, the reconstructed real, the signed rounding error, and the unit in the last place of that Q.n grid.
What Q-format means and how the stored integer is formed
Q-format, often written Q.n or Qn, is the convention used in Texas Instruments headers, ARM CMSIS-DSP, and countless FPGA toolchains for a binary fixed-point number with n bits to the right of the implied binary point. The real value represented by a stored integer I is I divided by two to the n, so the grid spacing — the resolution, or unit in the last place of that format — is exactly two to the minus n.
Encoding a decimal x therefore means computing x times two to the n and rounding onto an integer; decoding is a single divide by the same scale. Every representable value shares the same absolute step size, which is why audio codecs, motor-control loops, and lookup tables prefer it when they need deterministic rounding and cheap integer multiply-accumulates.
Search phrases such as decimal to fixed point converter, Q format converter, Q15 converter, and convert float to Q31 describe this exact job: take a human decimal, pick n, and read back the stored integer plus how much rounding moved the value.
A classic check is the decimal one-tenth with eight fractional bits: the scale is two hundred fifty-six, nearest rounding stores twenty-six, the reconstructed value is twenty-six over two hundred fifty-six, and the signed rounding error is the difference from one-tenth — exactly the triple this page is built to show.
Where a Q-format converter earns its keep
Firmware authors use a decimal to fixed-point converter when they paste a filter tap, a PID gain, or a unit conversion into a header and need the exact integer that will sit in a Q15 or Q31 variable. FPGA and HDL benches need the same number so a testbench stimulus matches the RTL datapath that never sees a float.
Game and audio tools convert normalized samples and animation weights onto a fixed grid before packing them into a binary asset, then want the rounding error printed beside the code so an artist can see whether eight fractional bits are enough. Classrooms that teach computer arithmetic need a deterministic oracle that shows resolution and error together, instead of a hand-wavy “multiply by two-fifty-six and round.”
What you can do with it
Firmware constants and DSP taps
Turn a design decimal into the Q15 or Q.8 integer that belongs in a header, and keep the rounding error next to the stored code for review.
FPGA and HDL testbenches
Generate the same fixed-point stimulus the RTL will see, with an explicit resolution of two to the minus n so scoreboards can tolerate one ulp.
Classroom computer-arithmetic checks
Show students the stored integer, the reconstructed real, and the signed error for any n, including the classic one-tenth example that is not exact in binary.
FAQ
What is the resolution of a Q.n number?
Resolution is exactly 2^-n: the step between two adjacent stored integers.
Which rounding mode should I use?
The chosen mode is echoed in the response.
Why can one-tenth not be stored exactly?
0.1 is not a dyadic rational. With eight fractional bits the nearest stored integer is 26, which reconstructs as 26/256 = 0.1015625.
How do I convert a decimal to Q15?
Choose 15 fractional bits. The tool multiplies your decimal by two to the 15th power, rounds it to an integer and shows the stored code, the value it really represents and the rounding error, ready to paste into firmware.
What is the largest number of fractional bits I can use?
Up to 52. The count must be a whole number from 0 to 52, and if the value times two to that power leaves the safe integer range, the conversion is refused rather than quietly losing its low bits.
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/dev/decimal-to-fixed-point \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"value":0.1,"fractional_bits":8}'const res = await fetch("https://api.kit.forhosting.com/dev/decimal-to-fixed-point", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"value": 0.1,
"fractional_bits": 8
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/decimal-to-fixed-point",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"value": 0.1,
"fractional_bits": 8
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/decimal-to-fixed-point", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"value":0.1,"fractional_bits":8}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"value":0.1,"fractional_bits":8}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/decimal-to-fixed-point", 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": 0.1,
"fractional_bits": 8
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.decimal_to_fixed_point",
"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_fractional_bits | 52 |
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
Embedded firmware, DSP kernels, FPGA datapaths, and game engines still store many signals as Q-format fixed-point integers instead of IEEE-754 floats: a chosen number of bits sit to the right of an implied binary point, so every stored integer is a multiple of a fixed resolution.
What Q-format means and how the stored integer is formed
This is not IEEE-754 floating point: there is no exponent field, no hidden leading one, and no gradual underflow. This endpoint implements that contract and nothing else. It does not emit C macros, it does not pack a full machine word with a chosen integer-bit width unless you interpret the stored integer yourself, and it does not convert to IEEE-754 bit patterns. Those are different search intents served by other tools.
Input contract, rounding modes, and the response fields
Missing fields, empty strings, non-finite values, a non-integer n, or an n outside zero through fifty-two also fail, and those failures are not billed. If the product of value and two to the n leaves the safe-integer range, the task is rejected rather than silently losing low bits. POST a JSON body with two required fields and one optional mode. value is the finite decimal to encode; it may arrive as a JSON number or as a numeric string, and the aliases decimal and number are accepted. fractional_bits is the integer n in Q.n, from zero through fifty-two inclusive, so that two to the n stays an exact JavaScript safe integer; aliases include frac_bits, n, and q. rounding is optional and defaults to nearest, which means half away from zero — the convention most DSP notes use, and not the same as JavaScript Math.round, which sends ties toward plus infinity. The other documented modes are toward_zero (truncate the scaled product), floor (toward minus infinity), and ceil (toward plus infinity); any other token fails with invalid_input. On success the body echoes value and fractional_bits, names the rounding mode, reports q_format as Q.n, and returns scale (two to the n), resolution (two to the minus n), stored (the integer code), stored_hex (signed-magnitude hex), reconstructed (stored over scale), rounding_error (reconstructed minus the original value), abs_error, a boolean exact when the rounded error is zero, and a short formula string. Pair the response with your own word-width check if you need to know whether stored fits in a signed sixteen-bit or thirty-two-bit register; this endpoint does not assume a total bit width, so the hex form is a signed magnitude, not two's complement of a hidden container.
Where a Q-format converter earns its keep
When the search intent is the IEEE-754 hex pattern of a float, use a floating-point bit-pattern tool; when the intent is a Q.n integer with its error and resolution, this is the contract.
Technical questions
How do I convert a decimal to a Q-format fixed-point integer?
Send a finite value and an integer fractional_bits n from 0 to 52. The API returns stored = round(value × 2^n), plus reconstructed, rounding_error, and resolution 2^-n.
What does the decimal to fixed-point converter cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.