Here is a higher level summary of Q notation that will help demystify the other good answers:
The post mentions "Q31" as a signed binary number, in this case with 32 total bits, and scaled to [-1, +1).
More generally with Q notation for fixed point hardware design (not limited to processor implementations with fixed precisions such as 8, 16, 32 etc but for any arbitrary scaling) the Q notation is given as follows:
$Qm.n$: signed representations
$UQm.n$: unsigned representations
In the above forms, m represents the integer bits and n represents the fractional bits. To add to the confusion, for signed numbers there are two primary conventions that either include or don't include the sign bit in m. That said,in this case ”Q31” would either be Q1.31 or Q0.31 depending on if we include the sign bit or not since we know the range is [-1,1).
I will use the convention of not including the sign bit for the remainder of this posting.
The total bit width not including the sign bit when used is $m+n$. $Qm.n$ is a $m+n+1$ bit word represented in fractional form as a ratio of two integers: The numerator is the integer value of the $m+n+1$ binary number, and the denominator is $2^n$.
As a simple example, $Q5.2$ represents an 8 bit signed word that has 2 fractional bits, and therefore has a step size of 0.25. To represent 6.25 for example, this would be $000110.01$ where I have shown an "implied" decimal place for clarity, which is really given by the denominator which is also implied in implementation--we are simply storing 8 bits. So here in this example, the numerator of the fraction of integers is $00011001$ binary which is $25$ decimal and the implied denominator is $4$ decimal resulting in $6.25$ as planned. The denominator is implied and not stored, but if we do change to a different Q format, the number stored must change to still represent $6.25$ accurately. For example if we wanted it to be $Q4.3$ this would still be 8 total bits but result in a bit shift to the left as $00110.010$ which still represents 6.25 here as 50/8.
In general, the range for represented numbers using Q notation is as follows:
Signed: $-2^m$ to $+2^m-2^{-n}$
Unsigned: $0$ to $2^m-2^{-n}$
And for either case the step size is given as $2^{-n}$.
This means the 32 bit signed number that is scaled to [-1, 1) is represented as $Q0.31$, and an unsigned 32 bit number would be $Q0.32$. The maximum value shown as 1) is specifically $1-2^{-31}$.
All that said, we can easily take the pain out of processing mathematical operations properly by remembering that each number represented is an integer divided by $2^n$. An arbitrary $Qm.n$ format number would be some integer $x$ within the range allowed by the $m+n$ bits divided by the denominator $2^n$ as:
$$\frac{X}{2^n}$$
Thus a product with different Q formats such as $Qm1.n1$ and $Qm2.n2$ would be as follows (prior to final scaling of the output if desired):
$$\frac{X_1}{2^{n1}}\frac{X_2}{2^{n2}} = \frac{X_1X_2}{2^{n1+n2}}$$
The Q format of this result would be $Qm3.n3$ where $m3=m1+m2$ and $n3=n1+n2$ with a total bit width required of $m3+n3+1$ (adding the sign bit).
We also see more easily how addition of different Q formats can be properly done (which is the rescaling often mentioned):
$$\frac{X_1}{2^{n1}} + \frac{X_2}{2^{n2}} = \frac{X_12^{n2}+X_22^{n1}}{2^{n1+n2}}$$
Which is simply aligning the implied decimal points prior to doing the addition.
Note that the integer $X_1$ multiplied by $2^k$ is a "shift left" of $k$ bits for positive $k$. If we multiply both numerator and denominator by $2^k$, meaning add $k$ to both $m$ and $n$ as $Q(m+k).(n+k)$, we have not changed the implied fractional representation, but we will have shifted the stored number $k$ bits (as we demonstrated with the simple 8 bit example representing 6.25).
Once a given mathematical operation is completed (with no rounding thus far as presented above), the output can be rounded as desired based on the maximum value represented and tolerable error either as truncation on the right or clipping on the left (when simply shifting) or rounding (when adding 0.5 first and then shifting).
I have demonstrated the more universal $Qm.n$ and $UQm.n$ formats which can include negative values for $m$ and $n$ and provides for arbitrary scaling and bit width changes from either MSB or LSB sides of the digital word, and provided a simple notation for properly keeping track of the radix and mathematical operations.
As a more detailed reference on fixed point arithmetic, see this nice write-up by Randy Yates: http://www.digitalsignallabs.com/fp.pdf
int64_t. $\endgroup$