Mr Goff logo

Computer Science

Fixed point binary

So far we have learned to represent positive and negative integers, but what about numbers with a fractional part.

We simply ned to allocate a certain nber of bits to represent numbers to the left of the decimal and a caertain number to thre right of the decimal. In this example we will use 4 digits either side of the decimal.

Example

For our example let's convert the decimal number 5.75 to 8 bit binary with 4 bits either side of the decimal point.

As you might expect the column headings to the right of the decimal oint carry on the pattern i.e colum headings halve going right anddouble going left.

8 4 2 1 .5 .25 .125 .0625
0 1 0 1 1 1 0 0

The process for cnverting to a fixed point number is the same as for converting a whole number.

Our rage of numbers we can represent is far smaller than with wholenumbers but we can also represent fractional portions down to sixteenths. If we change the number of bits allocated to the whole number part and the fractional part we affect the range and accuracy with which we can represent numbers.

3 bits for the whole numbers and 5 for the fractional part

4 2 1 .5 .25 .125 .0625 .03125
1 1 1 1 1 1 1 1

5 bits for the whole numbers and 3 for the fractional part

16 8 4 2 1 .5 .25 .125
1 1 1 1 1 1 1 1

With more bits for the whole number part we increase the range of numbers we can represent but decrease the accuracy with which we can represent the fractional part of numbers. The opposite is true if we increase the number of bits for the fractional part.

You can also have two's complement fixed point bnary and te idea is the same the most significant bit is negative. The number shown below would be -2.25.

-8 4 2 1 .5 .25 .125 .0625
1 1 0 1 1 1 0 0

Decimal numbers with a fractional part to fixed point binary practice

Click the button to get a number to convert

-8 4 2 1 .5 .25 .125 .0625



Computer Science Home