Fixed-Point Q-Format Converter
Convert real numbers ↔ fixed-point Qm.n representation.
Q0.15 · 16-bit · range -1 … 0.999969
resolution 2⁻15 = 3.0518e-5
This tool converts real numbers to signed fixed-point Qm.n representation and back — Q15, Q31, Q7.8 or any custom split up to 32 bits. It shows the raw two's-complement word, the value actually stored after rounding, the quantization error, and the format's range and resolution. Reference: 0.5 in Q15 is 0x4000, −1 is 0x8000.
How it works
Fixed-point stores a real number as an integer count of fixed-size steps: raw = round(value × 2ⁿ), decoded as value = raw ÷ 2ⁿ. With m integer bits and one sign bit the representable range is −2ᵐ … 2ᵐ − 2⁻ⁿ at a uniform resolution of 2⁻ⁿ. Unlike floating point, precision is constant across the range and arithmetic maps to plain integer instructions — which is why MCUs without an FPU and deterministic DSP pipelines still run on Q formats.
Values outside the range saturate (clamp) rather than wrap here, matching the saturating arithmetic DSP hardware applies, and the panel flags when that happened.
Worked example
raw = round(0.5 × 2¹⁵) = 16384 = 0x4000
−1.0 → −32768 = 0x8000 · 1.0 → clamped to 0x7FFF (max 1 − 2⁻¹⁵)
Parameters
| Parameter | Value | Notes |
|---|---|---|
| Layout | 1 sign + m int + n frac | total ≤ 32 bits |
| Encode | raw = round(v · 2ⁿ) | saturating at range ends |
| Decode | v = raw ÷ 2ⁿ | |
| Range | −2ᵐ … 2ᵐ − 2⁻ⁿ | |
| Resolution | 2⁻ⁿ | uniform across the range |
C implementation
#include <stdint.h>
#define Q15(x) ((int16_t)((x) * 32768.0f)) /* encode at compile time */
/* value = raw / 2^15; 0.5 -> 0x4000, -1.0 -> 0x8000 */
float q15_to_float(int16_t raw) { return raw / 32768.0f; }
int16_t q15_mul(int16_t a, int16_t b)
{
return (int16_t)(((int32_t)a * b) >> 15); /* Q15 x Q15 -> Q15 */
}FAQ
▸What does Qm.n mean exactly?
A signed fixed-point format with 1 sign bit, m integer bits and n fraction bits (1+m+n bits total). The stored integer counts steps of 2⁻ⁿ: value = raw / 2ⁿ. Q15 is shorthand for Q0.15 — a 16-bit format spanning −1 to 1−2⁻¹⁵, the workhorse of fixed-point DSP.
▸Why does encoding 1.0 in Q15 give 0x7FFF instead of an exact 1?
Q0.15 cannot represent +1.0: its maximum is 1 − 2⁻¹⁵ ≈ 0.99997. The converter clamps to the nearest representable value and tells you it did — the same saturation a DSP's saturating arithmetic performs.
▸How large is the quantization error?
At most half a step when rounding: 2⁻ⁿ/2. For Q15 that is about 1.5×10⁻⁵. The converter reports the exact error for your value — stored minus requested.
▸How do I multiply two Q15 numbers in C?
Multiply as 32-bit integers, then shift right by 15 (with rounding if desired): (int16_t)(((int32_t)a * b) >> 15). The intermediate product is Q30, and the shift renormalizes to Q15 — see the snippet below.
▸Is my data uploaded?
No. All conversion happens locally in your browser.