Fixed-Point (Q Format) Converter
Convert decimals to and from Q15, Q31, Q7.8, Q16.16 and any Qm.n fixed-point format, with exact values and quantisation error.
0x6000245760.752457600.000030517578125bit 15 is the sign · binary point sits between bit 15 and bit 14 · MSB (bit 15) left → LSB (bit 0) right
Standard formats
Format reference
| Format | Width | Min | Max | Resolution |
|---|---|---|---|---|
| Q15 | 16-bit signed | -1 | 0.999969482421875 | 0.000030517578125 |
| Q31 | 32-bit signed | -1 | 0.9999999995343387126922607421875 | 0.0000000004656612873077392578125 |
| Q7 | 8-bit signed | -1 | 0.9921875 | 0.0078125 |
| Q7.8 | 16-bit signed | -128 | 127.99609375 | 0.00390625 |
| Q16.16 | 32-bit signed | -32768 | 32767.9999847412109375 | 0.0000152587890625 |
| Q8.8 | 16-bit unsigned | 0 | 255.99609375 | 0.00390625 |
| Q4.12 | 16-bit signed | -8 | 7.999755859375 | 0.000244140625 |
| Q2.30 | 32-bit signed | -2 | 1.999999999068677425384521484375 | 0.000000000931322574615478515625 |
Every bound is exact: the value of a Q-format word is raw ÷ 2ⁿ, and because the divisor is a power of two the decimal expansion always terminates. Nothing on this page is a rounded preview.
How Q format works
A fixed-point number is an ordinary integer with an agreed binary point. In Q15 the stored word raw represents raw ÷ 2^15, so the hardware only ever does integer arithmetic and the scaling lives entirely in your head - or, better, in a typedef. Addition and subtraction need no adjustment at all: two Q15 values add as plain int16s.
Multiplication does. Multiplying two Q15 values produces a Q30 result, so you widen into a double-width accumulator and shift back down by 15. Omitting that shift is the single most common fixed-point bug, and it shows up as a result that is off by a factor of 2^15 rather than as anything that looks like a rounding problem.
Because the point is fixed, precision does not vary across the range the way it does in floating point: every representable value is an exact multiple of 0.000030517578125, at the top of the range and the bottom alike. That predictability is why control loops and audio filters prefer it - the error budget is a constant you can reason about, not a function of the signal.
The Qm.n notation trap
There are two live conventions and they disagree by one bit. Texas Instruments writes Qm.n with m counting integer bits excluding the sign, so a signed Q15.16 is a 32-bit word. ARM and the CMSIS-DSP documentation count the sign bit inside m. Both are in current use, which is why a coefficient table copied from one vendor's app note into another's toolchain is off by a factor of two.
This tool avoids the argument by making you state the total word width and the fraction count directly, then showing the resulting name. When you hand a format to someone else, give them the same two numbers rather than the label - “16-bit signed, 15 fraction bits” cannot be misread.
Fixed point versus IEEE 754
Floating point moves the binary point per value, spending some bits on an exponent to buy enormous dynamic range at constant relative precision. Fixed point spends every bit on the value itself, giving constant absolute precision over a narrow range. For an audio sample that is always between -1 and +1, the exponent field of a float is pure waste - which is exactly why Q15 and Q31 exist.
The practical trigger is hardware. A Cortex-M0 or M3 has no FPU, so a float multiply is a software routine costing tens of cycles while a Q15 multiply is one MUL and one shift. If you are on a part with an FPU, use floats and stop thinking about it. If you are not, or you are writing a filter whose error budget has to be provable, fixed point is the right answer. The IEEE 754 converter shows the other side of the same trade.
Code Examples
#include <stdint.h>
#define Q15_FRAC 15
#define Q15_ONE (1 << Q15_FRAC)
/* float -> Q15 with rounding and saturation */
int16_t to_q15(float x) {
int32_t raw = (int32_t)(x * Q15_ONE + (x >= 0 ? 0.5f : -0.5f));
if (raw > 32767) raw = 32767;
if (raw < -32768) raw = -32768;
return (int16_t)raw;
}
float from_q15(int16_t q) { return (float)q / Q15_ONE; }
/* Q15 * Q15 -> Q15: the >> 15 re-normalises the Q30 product */
int16_t mul_q15(int16_t a, int16_t b) {
return (int16_t)(((int32_t)a * (int32_t)b) >> Q15_FRAC);
}Frequently Asked Questions
What is Q format?
Q format is a notation for fixed-point numbers. A Qm.n value is an integer stored in a normal machine word where the binary point is fixed n bits from the right, so the stored word represents raw / 2^n. Q15 means 15 fraction bits in a 16-bit signed word, which gives a range of -1 up to just under +1.
Does Qm.n include the sign bit?
It depends whose convention you are reading. Texas Instruments writes Qm.n with m integer bits excluding the sign, so a signed Q15.16 is 32 bits. ARM and CMSIS count the sign bit inside m, making Q15.16 a 32-bit word too but for different bookkeeping. This tool sidesteps the ambiguity: you set the total width and the fraction count explicitly, and it prints the resulting Qm.n name.
What is the difference between fixed point and floating point?
Floating point moves the binary point per value, trading precision for range. Fixed point pins it, so precision is constant across the whole range and every operation is plain integer arithmetic. That is why DSPs, audio codecs and microcontrollers without an FPU use it - a fixed-point multiply is one instruction.
What is the resolution of Q15?
2^-15, or 0.000030517578125. Every representable Q15 value is an exact multiple of that step, and this converter prints the exact value rather than a rounded preview - a real difference at Q31, where the step is smaller than a double's error on a decimal literal.
Why did my value saturate?
Q15 cannot represent 1.0: the range is -1 to 32767/32768, or 0.999969482421875. Anything at or above 1.0 saturates to the maximum. This is the single most common fixed-point surprise, and it is why filter coefficients are often scaled down before conversion.
How do I multiply two Q15 numbers?
Multiply the raw integers into a 32-bit accumulator, then shift right by 15 to put the binary point back. Two Q15 values multiply to a Q30 result, so the shift is what re-normalises it. Skipping the shift is the classic off-by-2^15 bug.
What is quantisation error?
The difference between the value you asked for and the nearest representable one. This page prints it exactly for every conversion. Rounding to nearest halves the worst-case error compared with truncation, which is why DSP libraries round rather than truncate.
How are negative fixed-point numbers stored?
As two's complement, exactly like any signed integer - the fixed-point interpretation only changes where you imagine the binary point. -0.5 in Q15 is raw -16384, stored as 0xC000.
What is Q31 used for?
32-bit signed audio and high-resolution DSP. CMSIS-DSP's q31_t is the standard type for filter states on Cortex-M, and 24-bit audio is usually carried left-aligned in a Q31 word.
Related Tools
Hex to Float & IEEE 754 Converter
Convert a hex or binary bit pattern to the float it encodes, and any decimal number to its IEEE 754 bits.
Two's Complement Calculator
Calculate two's complement representation for signed integers.
Bitmask Generator & Register Workbench
Build, paste and visualize bitmasks at 8, 16, 32 or 64 bits - then generate the set, clear, toggle and field-extract code for them.
This tool runs entirely in your browser - nothing you enter is uploaded or stored.