Fixed point numbers and fixed point arithmetic

Introduction

A fixed point number is a value with a integer and fractional part.

Internally, these numbers are stored using a binary representation, where the integer and fractional part are described by a fixed range of binary digits.

The binary representation:

integer partbinary pointfractional part
...252423222120.2-12-22-32-42-5...
...32168421.1/21/41/81/161/32...

The number of binary digits assigned to the integer part may be different to the number of digits assigned to the fractional part.

There are many different fixed point representations used, so to identify the representation this general notation is used:

<number of bits assigned to integer part> : <number of bits assigned to fractional part>

For example, a fixed point number using a "12:4" notation has 12 bits used by the integer part and 4 bits used by the fractional part.

This may be represented in a 16-bit value as follows:

Bit IndexPosition
of binary point
Bit index
1514131211109876543210
Integer partFractional part

Positive and negative values can also be represented as fixed point numbers. Where positive and negative numbers are represented by the same notation, one bit is used to hold the sign of the number.

An example representation for a positive & negative fixed point number:

Bit IndexPosition
of binary point
Bit index
1514131211109876543210
SignInteger partFractional part

Advantages:

Disadvantages:

overflow
A "overflow" will occur when the result of a arithmetic operation is too large to fit into the fixed representation of a fixed point number
underflow
A "underflow" will occur when the result of a arithmetic operation is too small to fit into the fixed representation of a fixed point number