| |||

Home > AXD > AXD Facilities > Data formatting > Q-format |

Q-formats are bit-level formats for storing numeric values. A Q-format allows you to specify:

the number of bits used to represent values

the numeric range within which all values fall.

The total number of bits you allow for storing a value determines the maximum precision with which a value can be defined. You can also regard it as determining the resolution, or smallest difference that can be distinguished between values.

In a Q-format you specify how many bits represent an integer value, and how many further bits represent subdivisions within each integer value. You can in effect specify ranges. For example:

-1024 to (almost) +1024, where the most significant 11 bits represent a signed integer value

0 to (almost) +64, where the most significant 6 bits represent an unsigned integer value

-1 to (almost) +1, where the most significant bit represents the sign.

In each case, all the remaining bits represent fractions between each integer value, and (almost) means a value just one least-significant-bit less than the value given.

The form of a Q-format is Qn.m, where n is the number of bits
before a notional *binary point*, and m is the
number of bits that follow it. You can choose signed Q-format for ranges
of values divided equally either side of zero, or unsigned Q-format
for values that range upwards from zero.

For example, a 16-bit halfword can hold values in a signed Q4.12 format. This covers the range -8 to (almost) +8, with 65,536 unique values available in that range.

U Q15 is shorthand for unsigned Q1.15. This is a format for 16-bit values that gives 65,536 unique values in the range 0 to (almost) +2.

Q31 is shorthand for signed Q1.31. This is a format for 32-bit values that gives 4,294,967,296 unique values in the range -1 to (almost) +1.