Data Representation: Fixed point binary to decimal

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

We simply need to allocate a certain number of bits to represent numbers to the left of the decimal and a certain number to the 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



Fixed point binary to decimal

This is essentially the same as for normal binary numbers but with different column headings but we still just add up all the column headings where there is a 1 in the column.

Example

For our example let's convert the decimal number 01011100 in 8 bit binary with 4 bits either side of the decimal point to a decimal number with a fractional part.

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

4 + 1 + 0.5 + 0.25 = 5.75

Be sure to read any question on fixed point numbers carefully to check how many bits are used for the whole number part and how many for the fractional part. Also keep an eye out for whether the question says the number is in two's compliment or not.

Fixed point binary practice to decimal numbers with a fractional part

Click the button to get a number to convert

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



© All materials created by and copyright S.Goff