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.

(1)
$$x_{FRACTION} = x_{INTEGER}/ 2^{N-1}$$
(2)
$$x_{INTEGER} = x_{FRACTION}* 2^{N-1}$$

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

Word
Value
Integer
Value
Fractional
Value
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.

(3)
$$a = <sa_{14}a_{13}...a_1a_0>$$

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

(4)
$$a = a_{{14}}2^{{14}} + a_{{13}}2^{{13}} + ... + a_12^1 + a_02^0$$

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

(5)
$$b = a_{{14}}2^{{-1}} + a_{{13}}2^{{-2}} + ... + a_12^{{-14}} + a_02^{{-15}}$$

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.