# 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

• The position of the binary point is implied by the notation, and no bits are used to represent it.
• This notation describes a positive number range.
• The minimum value that can be represented is 1 (base 2), which is 1/16 (base 10).
• The maximum value that can be represented is 1111111111111111 (base 2), which is 4096.9375 (base 10).

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

• In this example:
• When the sign bit is "1" the number is negative.
• When the sign bit is "0" the number is positive.
• The minimum value that can be represented is 1111111111111111 (base 2) -2047.9375,
• The maximum value that can be represented is 01111111111111111 (base 2) +2047.9375.
• The above representation is the same as 2's complement numbers. Therefore existing CPU opcodes can be used to test for signedness.