# Fundamentals of Data Representation: Binary fractions

 ← Binary number system Binary fractions Two's complement →

## Binary Fractions

So far we have only looked at whole numbers (integers), we need to understand how computers represent fractions.

You should have learned at Primary School how a decimal fraction works:

10 1 ${\displaystyle {\frac {1}{10}}}$ ${\displaystyle {\frac {1}{100}}}$
${\displaystyle 10^{1}}$ ${\displaystyle 10^{0}}$ ${\displaystyle 10^{-1}}$ ${\displaystyle 10^{-2}}$
1 2 . 7 5

As you can see, the column headings have been extended to ${\displaystyle 10^{-1}={\frac {1}{10}}}$ and ${\displaystyle 10^{-2}={\frac {1}{100}}}$. We can do the same thing in binary with the column headings ${\displaystyle 2^{-1}={\frac {1}{2}}}$, ${\displaystyle 2^{-2}={\frac {1}{4}}}$, and so on. The number 12.75 in 8 bit binary with 4 bits after the binary point is therefore 8 + 4 + 0.5 + 0.25:

8 4 2 1 ${\displaystyle {\frac {1}{2}}}$ ${\displaystyle {\frac {1}{4}}}$ ${\displaystyle {\frac {1}{8}}}$ ${\displaystyle {\frac {1}{16}}}$
${\displaystyle 2^{3}}$ ${\displaystyle 2^{2}}$ ${\displaystyle 2^{1}}$ ${\displaystyle 2^{0}}$ ${\displaystyle 2^{-1}}$ ${\displaystyle 2^{-2}}$ ${\displaystyle 2^{-3}}$ ${\displaystyle 2^{-4}}$
1 1 0 0 . 1 1 0 0

Notice that for the same number of bits after the point, the binary fraction provides less accuracy. It can only take 4 different values, whereas the decimal number can have 100 different values with two digits. You'll see in a moment how this can cause trouble.

Example: converting decimal to binary decimal

We are going to convert the number 6.125 into a binary fraction by using the grid below

8 4 2 1 ${\displaystyle {\frac {1}{2}}}$ ${\displaystyle {\frac {1}{4}}}$ ${\displaystyle {\frac {1}{8}}}$ ${\displaystyle {\frac {1}{16}}}$
0 1 1 0 . 0 0 1 0

This seems simple enough as 6.125 = 4 + 2 + 0.125, but what about this more interesting number: 6.4

8 4 2 1 ${\displaystyle {\frac {1}{2}}}$ ${\displaystyle {\frac {1}{4}}}$ ${\displaystyle {\frac {1}{8}}}$ ${\displaystyle {\frac {1}{16}}}$
0 1 1 0 . 0 1 1 0

But this doesn't look right?! This number isn't correct as it only reaches 4 + 2 + 0.25 + 0.125 = 6.375, we need more bits for the binary fraction places. However, a computer might restrict you to the number of bits you can use, so we'll use the number closest to the one we were aiming for. You could feel a bit annoyed at this, but don't worry, you make this compromise every time you try to represent ${\displaystyle {\frac {1}{3}}}$ with the decimal factions, 0.33333333.

So you might ask how a computer does complicated mathematics if it struggles so hard with fractions. The answers we have looked at so far have only used one byte, computers can use far more space than this. They can also manipulate the number of bits they have been given in two ways:

• increase the number of bits to increase range of number
• increase number of bits after the decimal point to increase accuracy

In practice they will also use clever techniques such as floating point numbers that you will meet in A2.