Q-Format to Decimal Converter
Convert Q-format fixed-point numbers without 32-bit JavaScript rounding or sign-bit errors. Choose the input radix explicitly, use signed or unsigned interpretation, and inspect the exact stored bits and calculation.
Converter
Number of integer bits
Number of fractional bits
Choosing the radix prevents values such as 1010 from being interpreted ambiguously.
Enter a hexadecimal raw Q-format value
How to Use This Tool
Select Q-Format
Choose a preset like Q15 or Q31, or enter custom m and n values for your specific format
Enter Your Value
Choose binary, hexadecimal, or decimal explicitly, then enter the stored integer or bit pattern
View Results
See the decimal equivalent along with step-by-step calculation breakdown
Q-Format Formula
decimal = integer_value / 2nIn Q-format notation Qm.n, the number is represented with:
- m integer bits (excluding the sign bit for signed numbers)
- n fractional bits
- For signed numbers, an additional sign bit using two's complement
The total number of bits is m + n for unsigned, or m + n + 1 for signed numbers (including the sign bit).
For example, Q15 (or Q0.15) uses 16 bits total: 1 sign bit + 0 integer bits + 15 fractional bits. The range is -1.0 to +0.999969482421875 (approximately +1.0 - 2-15).
Worked Q-format conversion examples
Q0.15 positive value
Select Q15, hexadecimal input, and enter 0x4000. The raw integer is 16,384. Dividing by 215, or 32,768, gives exactly 0.5. The leading bit is zero, so signed and unsigned interpretation produce the same result for this value.
Q0.15 negative value
With signed mode enabled, 0xC000 has its sign bit set. Interpreting the 16-bit pattern as two's complement gives -16,384. The same scale division produces -0.5. In unsigned mode the bit pattern instead represents 49,152 and converts to 1.5.
Q16.16 beyond 32 bits
Signed Q16.16 uses 33 total bits under the notation used here: one sign bit, 16 integer bits and 16 fractional bits. This converter uses arbitrary-width integer operations, so the sign bit remains bit 32 instead of wrapping to bit zero as it would with JavaScript's ordinary bitwise operators.
Signed ranges, storage width and notation
Q-format names are not perfectly standardized across every vendor. This calculator uses Qm.n to mean m magnitude/integer bits and n fractional bits, with a separate sign bit when signed mode is enabled. Under that convention, signed Q0.15 occupies 16 bits and signed Q1.15 occupies 17 bits. Some data sheets count the sign bit inside the number before the dot and may call a 16-bit layout Q1.15. Always compare the displayed total width with the type in your firmware, DSP library, codec, or hardware manual rather than relying on the label alone.
For an unsigned value, the raw range is zero through 2m+n - 1 and the real range is zero through 2m - 2-n. For a signed two's-complement value, the real range is -2m through 2m - 2-n. The smallest step, often called the resolution or least significant bit value, is 2-n. Increasing fractional bits improves resolution but leaves fewer bits for integer magnitude at a fixed storage width.
Hexadecimal and binary inputs are treated as stored bit patterns. Decimal mode accepts a non-negative raw storage integer, or a negative signed integer when signed mode is on. Values that do not fit the selected width are rejected instead of silently truncating their high bits. That makes overflow visible and prevents a value intended for one Q layout from accidentally appearing valid in another.
Rounding, overflow and implementation checks
Converting a real number into Q-format requires a rounding policy. Multiply the real value by 2n, then apply the rule used by your system: truncation, round to nearest, round half away from zero, or round to nearest even. Different policies can differ by one least significant bit. This page converts an existing stored value back to decimal, so it does not invent a rounding rule; the bit pattern already determines the result.
Overflow behavior also belongs to the producer of the value. Some processors wrap modulo the storage width, while fixed-point libraries may saturate at the minimum or maximum. The converter deliberately rejects out-of-range input rather than simulating either behavior. If you are debugging an overflow, first reduce the value to the exact stored width according to the target system, then enter the resulting binary or hexadecimal pattern here.
A useful verification routine is to check three points for every layout: zero, the maximum positive pattern, and the sign-bit-only pattern. For signed Q0.15 these are 0x0000 = 0, 0x7FFF = 0.999969482421875, and 0x8000 = -1. If those match your specification, test one ordinary positive and negative sample before relying on a larger conversion batch.
Frequently Asked Questions
What is Q-format and where is it used?
Q-format is a fixed-point number representation used extensively in digital signal processing (DSP), embedded systems, and audio/video codecs. It allows efficient arithmetic on processors without floating-point units by representing fractional values as scaled integers.
What's the difference between Q15 and Q1.15?
Under this calculator’s explicit-sign convention, Q15 (Q0.15) has 0 integer bits and 15 fractional bits, giving a range of -1 to nearly +1 in 16 total bits. Q1.15 adds one integer-magnitude bit, extends the range to -2 through nearly +2, and therefore uses 17 total bits when signed. Some vendor documents count the sign bit inside m, so always verify the stated storage width.
How do I convert a decimal back to Q-format?
To convert a decimal to Q-format, multiply by 2^n (where n is the number of fractional bits), then round to the nearest integer. For example, 0.5 in Q15 would be 0.5 x 32768 = 16384 (0x4000 in hex).
What input formats does this converter accept?
Choose binary, hexadecimal, or decimal explicitly. Binary accepts an optional 0b prefix, hexadecimal accepts an optional 0x prefix, and decimal accepts a raw non-negative storage integer or a negative integer in signed mode. The explicit selector means 1010 is never guessed as both binary and decimal.
Why does signed hexadecimal sometimes become negative?
Signed mode reads the highest bit of the selected total width as a two’s-complement sign bit. If that bit is one, the raw value is reduced by 2 raised to the total bit count before the fractional scale is applied. Turn signed mode off when the stored field is genuinely unsigned.
Does the converter work correctly above 32 bits?
Yes. Parsing, sign extraction, range validation and scaling use BigInt rather than JavaScript’s 32-bit bitwise operators. Custom layouts may use up to 64 total bits, and the displayed decimal expansion is calculated from the integer ratio rather than rounded through a 32-bit operation.
Related Tools
More free calculators and tools you might find useful