Numerical Formats

Integer/Fractional Relationship

The same two's complement N-bit word may represent an integer value or a fractional value. The same arithmetic and logic hardware may be used with either format. We just interpret the results differently.

\begin{equation} x_{FRACTION} = x_{INTEGER}/ 2^{N-1} \end{equation}
\begin{equation} x_{INTEGER} = x_{FRACTION}* 2^{N-1} \end{equation}

For N = 16 bits, 2N-1 = 32768

0x8000 -32768 -1.000000
0xA000 -24576 -0.750000
0xC000 -16384 -0.500000
0xE000 -8192 -0.250000
0x0000 0 0.000000
0x2000 8192 0.250000
0x4000 16384 0.500000
0x6000 24576 0.750000
0x7FFF 32767 0.999969

1.15(Q15) Signed Fractional Format


To understand how Q15 numbers are handled, let's assume we have a 16-bit integer in 2's complement format where s is a sign bit and an is the digit at bit n.

\begin{equation} a = <sa_{14}a_{13}...a_1a_0> \end{equation}

For a positive integer a, the value of the number a is:

\begin{equation} a = a_{{14}}2^{{14}} + a_{{13}}2^{{13}} + ... + a_12^1 + a_02^0 \end{equation}

For a Q15 number, the weightings of each bit change. Let b = a / 215, then the value of a positive Q15 number b is:

\begin{equation} b = a_{{14}}2^{{-1}} + a_{{13}}2^{{-2}} + ... + a_12^{{-14}} + a_02^{{-15}} \end{equation}

The maximum negative value that can be handled is 0x8000 = -1.000000000000 and the maximum positive value is 0x7FFF = 0.999969482422. Zero is represented by 0x0000.

For more information on the Q format see this Wikipedia article.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.