What is Q-format fixed point?
A fixed-point word stores an integer while the format supplies an implied binary point. With F fractional bits, stored integer N represents N ÷ 2F. The binary point is not stored in memory, so software and hardware must agree on the width, signedness and scale.
This page describes formats with total word width and fractional-bit count because Q notation is not universal. Here, signed Q8.8 means a 16-bit two’s-complement word with eight fractional bits; the displayed width and scale remove any ambiguity.
Fixed-point arithmetic rules
Addition and subtraction are direct integer operations when both operands use the same scale, although the result can overflow. Multiplication adds the operands’ fractional-bit counts, so the wide product must be shifted and rounded to return to the target format. Division requires a scaling shift before integer division. This calculator models those operations using exact rational values and applies the selected rounding and overflow policies at the storage boundary.
Saturation versus wrapping
Saturation holds an out-of-range result at the nearest limit. Wrapping keeps only the selected number of low bits, like modular fixed-width integer arithmetic. DSP systems often prefer saturation because a large positive signal wrapping into a negative value can be disruptive.
Mixed-format arithmetic: when A, B and the result differ
Real firmware rarely keeps every value in one format. A Q1.15 filter coefficient multiplies a Q8.8 sensor reading. An unsigned 8-bit gain scales a signed signal. A Q16.16 position is divided by a Q8.8 speed. Tick Give A, B and the result their own formats to give each operand and the result its own width, fractional bits and signedness. The calculator then shows the integer steps a processor or FPGA would take.
Adding and subtracting: line up the binary points first
Two stored integers can only be added when they share a scale. Shift the operand with fewer fractional bits left until both have the same count, then add. In Q1.15 + Q8.8, the Q8.8 value is shifted left by 7 bits so both sit at 15 fractional bits. The exact sum needs one more integer bit than the larger operand to absorb the carry. Storing it back in Q8.8 means shifting right by 7 bits and rounding.
Multiplying: fractional bits add up
Multiply the two stored integers directly. The product’s fractional bits are the sum of the operands’ fractional bits, and its width is the sum of their widths. Q15 × Q15 gives an exact 32-bit product with 30 fractional bits. Two signed operands leave two sign bits at the top, which is why DSP instructions often shift the product left by one and why −1 × −1 is the one case that then overflows. Turning the product back into Q15 is a right shift by 15 with your chosen rounding.
Dividing: pre-shift the dividend
Integer division removes fractional bits: A’s fractional bits minus B’s. To get F fractional bits in the quotient, shift the dividend left by F − A’s fractional bits + B’s fractional bits before dividing. For Q16.16 ÷ Q8.8 into Q16.16, that is 16 − 16 + 8 = 8 bits. The remainder is then rounded according to the rounding policy.
Choosing the result format
Keep full precision shows the smallest format that holds every possible exact sum, difference or product. Use it to size an accumulator or an intermediate register. Choosing a narrower result format shows the rounding error, and whether the overflow policy had to saturate or wrap.
Converting to and from Q format by hand
Decimal to Q15. Multiply by 2¹⁵ = 32,768, round to a whole number, and store that integer. For 0.1: 0.1 × 32,768 = 3,276.8, which rounds to 3,277, or 0x0CCD. The stored value is 3,277 ÷ 32,768 = 0.100006103515625, so the rounding error is about 6.1 × 10⁻⁶, a fifth of one LSB.
Raw word to decimal. Read the word as a two’s-complement integer, then divide by 2 to the power of the fractional bits. The 16-bit word 0xFF38 is −200 as a signed integer, so in Q8.8 it means −200 ÷ 256 = −0.78125. Read as unsigned UQ8.8, the same bits would mean 65,336 ÷ 256 = 255.21875, which is why the signedness must always be known.
Q notation: Q15, Q1.15 and Q0.15
The same format goes by several names, which is a common source of bugs. A signed 16-bit word with 15 fractional bits is:
- Q15, giving only the fractional bits. Common in DSP documentation.
- Q1.15, where the 1 counts the sign bit, so the two numbers add up to the word width. This page uses that style.
- Q0.15, where the sign bit isn’t counted and 0 is the number of integer bits.
Unsigned formats are usually written with a U, such as UQ8.8 or UQ0.16. When you read a datasheet or someone else’s code, confirm the total width and whether the value is signed, rather than relying on the letters alone.
Example: choosing a format for a temperature sensor
A sensor reports −40 °C to 125 °C and you have a 16-bit signed register. The largest magnitude, 125, needs 7 integer bits plus the sign bit, leaving 8 fractional bits. That is Q8.8, with a range of −128 to 127.996 and a step of 1/256 ≈ 0.0039 °C. Using 9 fractional bits would give a maximum of about 63.998, too small for 125. The format picker above does this check exactly, and it can also tell you the smallest word that reaches a required step size.
Fixed-point arithmetic in C
A typical Q15 multiply widens to 32 bits, rounds, shifts back and saturates:
int16_t q15_mul(int16_t a, int16_t b)
{
int32_t p = (int32_t)a * b; /* Q2.30 product */
p = (p + (1 << 14)) >> 15; /* round, back to Q15 */
if (p > INT16_MAX) p = INT16_MAX; /* only −1 × −1 gets here */
return (int16_t)p;
}Without the saturation line, −1 × −1 would produce 32,768 and wrap to −32,768, turning +1 into −1. Right-shifting a negative number is an arithmetic shift on mainstream compilers, but check your toolchain. For coefficient tables, the Convert a list to a C array tool generates the initialiser for you.
Where Q-format calculations are used
Digital signal processing
Audio filters and control loops use Q15 or Q31 coefficients when predictable resolution and fast integer multiply-accumulate operations matter.
Embedded sensors and motor control
A register may store temperature, speed or current as a signed integer with an implied scale. Decoding its hexadecimal word requires both the two’s-complement width and the number of fractional bits.
Graphics, games and deterministic simulation
Formats such as Q16.16 provide a consistent step size across platforms and avoid some differences introduced by hardware floating-point behavior.
Quantised machine learning
Low-precision inference maps real values onto integer grids. Range, scale, rounding and saturation determine the error introduced by that mapping.
How to choose a fixed-point format
Reserve enough integer bits for the largest expected magnitude, including the sign position for signed values. Allocate the remaining bits to the fraction. Every additional fractional bit halves the resolution, but it also halves the available range. Test boundary values and intermediate arithmetic—not only the final output—because multiplication and accumulation can require guard bits.