COMPUTER SCIENCE / NUMBER SYSTEMS

Q-Format Fixed-Point Converter and Arithmetic Calculator

Encode decimal values as Q-format words, decode binary or hexadecimal registers, measure quantisation error and model fixed-point arithmetic with explicit rounding and overflow behavior.

Configure the fixed-point format

Presets
Fixed-point arithmetic
Mixed examples

Convert a list to a C array

Paste filter coefficients, a lookup table or any list of decimals. Each value is converted with the format, rounding and overflow settings above.

Choose a format for your range

Enter the smallest and largest values you need to store. The picker finds the most fractional bits that still fit, so you get the finest resolution for the word width.

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.

Frequently asked questions

What does Q15 mean?

In a common convention, Q15 means a signed 16-bit word with 15 fractional bits. Its resolution is 1/32768 and its range is −1 through 32767/32768. Because notation varies, always confirm total width and signedness.

Why can Q15 represent −1 but not +1?

A signed 16-bit word ranges from −32768 to 32767. Dividing by 32768 gives −1 exactly, while the largest positive value is one step below +1.

How do I add two numbers in different Q formats?

Shift the operand with fewer fractional bits left until both have the same number, add the integers, then shift the sum to the result format. To add Q1.15 and Q8.8, shift the Q8.8 value left by 7 bits, add, and shift right by 7 bits with rounding if the result is stored as Q8.8.

What format is the product of two Q15 numbers?

The exact product of two 16-bit Q15 values is a 32-bit value with 30 fractional bits, often called Q2.30. Shift it right by 15 bits, with rounding, to return to Q15, or left by 1 bit to get Q1.31.

What is quantisation error?

It is the stored fixed-point value minus the requested real value. A value between grid points must be rounded to a multiple of one LSB.

What happens when fixed-point arithmetic overflows?

That depends on the chosen policy. Saturation clamps to a limit, wrapping keeps the low bits, and rejection reports that the value cannot be represented.

Is fixed point more accurate than floating point?

Neither is universally more accurate. Fixed point has constant absolute resolution across its range; floating point provides a much wider dynamic range with precision that changes with magnitude.

How do I convert a decimal to Q15?

Multiply by 32,768, round to the nearest whole number and store it as a signed 16-bit integer. For example, 0.1 becomes 3,277, or 0x0CCD. Values must be from −1 up to just under +1.

What is the difference between Q15, Q1.15 and Q0.15?

They usually describe the same signed 16-bit format with 15 fractional bits. Q15 names only the fractional bits, Q1.15 counts the sign bit as an integer bit, and Q0.15 doesn’t count it.

How many fractional bits should I use?

Use as many as possible while the largest value you need still fits. Each extra fractional bit halves the step size and halves the range. The format picker on this page finds the best split for a given range and word width.

How do I generate a C array of fixed-point coefficients?

Set the format above, paste your coefficients into Convert a list to a C array and copy the result. It also reports the largest rounding error and any values that overflowed.

← All number-system calculators