Binary Fractions

Introduction

Integers can be quite easily represented in binary. However, it is a little harder to represent decimal numbers that have a fractional part. For example 123.456 and 0.4546. There are two ways of doing this:
  1. Fixed point notation
  2. Floating point notation 
The following tutorial contains excellent detailed information on the first type. The floating point notation is covered on another page in this site.

Fixed point notation

For a definition visit this Wikipedia page

This type of notation is where the decimal point (often called the radix point) is in a fixed position and a set number of bits is used to express the number. For example, using eight bits, four could be used for the non-fractional part of the number and four for the fractional part. Here are some examples:
  • 1111.1111
  • 1011.0011
  • 0000.0001
It is helpful to look at how fractions work in base ten before looking at base two.

Decimal fractions

The table below show the relationship between the powers of ten and the integer made up by them.

 102 = 100s
 101 = 10s
 100 = 1s
 1  2  3

123 = 1 x 102 + 2 x 101 + 3 x 100

Base 10 positional notation

A fractional decimal can be treated in the same way using what is called base 10 positional notation. For example the number 123.456.

 102 = 100s
 101 = 10s
 100 = 1s
decimal point
10-1 = tenths
or 0.1
10-2 = one hundreths
or 0.01
10-3 = one thousanths
or 0.001
 1  2  3  .  4  5  6

123.456 = 1 x 102 + 2 x 101 + 3 x 100 + 4 x 10-1 + 5 x 10-2 + 6 x 10-3

123.456 = 100 + 20 + 3 + 0.4 + 0.05 + 0.006

Base 2 positional notation

In the same way base 2 positional notation can be used with binary numbers. For example, using a six bit system, the number 111.111 can be represented like so,

Decimal values
 22 = 4s
 21 = 2s
 20 = 1s
radix point
2-1 = halves
or 0.5
2-2 = quarters
or 0.25
2-3 = eigths
or 0.125
   1  1  1  .  1  1  1

So, 111.111 converted to a decimal is: 1 x 4 + 1 x 2 + 1 x 1 + 1 x 0.5 + 1 x 0.25 + 1 x 0.125 = 7.875

Note that the decimal point is called the radix point.

Converting from decimal to binary

It is possible to convert a decimal fraction to a binary one. For example the number 12.75. The table below (from the first tutorial link at the top of this page) will help. Note that it uses 8 bits to represent the number, not counting the radix point.

Powers of 2 23 22 21 20 . 2-1 2-2 2-3 2-4
  Decimal value 8 4 2 1 . 0.5 0.25 0.125 0.0625
How many of each (0 or 1)?
       
.
       

Looking at the table we can see that we can make up 12 using one 8 plus one four. We can make up 0.75 with one 0.5 plus one 0.25. This can be written like so:
12.75 = 1 x 8 + 1 x 4 + 0 x 2 + 0 x 1 + 1 x 0.5 + 1 x 0.25
=> 1100.110

Note that unused powers of 2 positions must be filled with zeros.

Adding binary fractions

Binary fractions can be added just like ordinary binary numbers. For example, using an eight bit system 0110.1010 (6.625) and 0011.1000 (3.5) added together equals 1010.0010 (6.125).


Decimal value
   8
 4  2  1  .  0.5  0.25  0.125  0.0625  
carry  0  1  1  1  1            decimal value
    0
 1  1  0  .  1  0  1  0  6.625
    0
 0  1  1  .  1  0  0  0  3.5
result
  1
 0  1  0  .  0  0  1  0  6.125

Limits in range and precision

Note, in an eight bit system the maximum number that can be expressed by the ones to the left of the decimal point is 1111 or 15 and the maximum fractional part to the right of the decimal point is 1111 or 0.9375. This means overflow will occur if the sum is greater than 15.9375 (15 + 0. 9375). This system is said to have a range of 0 to 15.9375. Also, the smallest value that can be represented is 0000.0001 or 0.0625 (2-4). This can be said to be the smallest unit. All other values are powers of two multiples of it. For example 0.5 is 8 x 0.0625. This means that there are some numbers that can not be represented. For example one between 0.125 and 0.0625, and there are an infinite number of them. The maximum 'units' of precision a representation can have is 2n where n is the number of bits used. So for eight bits 28 = 256 numbers (binary combinations of 1s and 0s) can be represented in the range 0 to 15.9375.

Using more bits will increase the range and precision. For example if 16 is used 216 or 65,536 numbers can be represented and the smallest unit is 2-8 or 0.00390625. The range is approximately 0 to 256. More numbers can be represented and the precision is greater, but there are still an infinite number of numbers that can not be represented i.e. any that are not a power of two multiple of 0.00390625. For example 3 x 0.00390625.

More bits can be used to represent a number and this would lead to greater precision and range, but there will always be some numbers that can not accurately be expressed.