12.4 Integer Representations
The Q15 data type can be represented by the 16-bit integer data type
(short
) and the Q31 data type can be represented by the 32-bit
integer data type (int
). These types are necessary when using the
compiler's DSP built-in functions (see 29 Built-In Functions). Typedefs are
useful for Q15 and Q31 as follows:
typedef short q15;
typedef int q31;
The four 64-bit accumulators in the DSP-enhanced core can be represented by the
long long int
data type.
typedef long long int a64;
To initialize Q15 variables, multiply the fractional value (for example, 0.1234) by
0x1.0p15
. To initialize Q31 variables, programmers can multiply the
fractional value by 0x1.0p31
.
Ex: /* Q15 Example */
typedef short q15;
q15 a = 0.1234 * 0x1.0p15;
/* ------------------------------------------------------ */
Ex: /* Q31 Example */
typedef int q31;
q31 b = 0.2468 * 0x1.0p31;