Binary 4 – Floating Point Binary Fractions 1

Greg's Study Journal
24 followers
1 Video View·Nov 8, 2022
Binary 4 – Floating Point Binary Fractions 1
This is the fourth in a series of videos about binary.
I'm going to talk about how we can represent real numbers
using floating point binary notation.
Most modern computers use floating point binary
to represent real numbers.
Why? Because floating point binary
makes particularly efficient use of a computer register
when it comes to representing either extremely large values,
extremely small values,
or values that require a high degree of precision.
Floating point binary is similar
to standard scientific notation in base 10.
It's worth getting to know this first.
Here are some special values in scientific notation.
You might recognise some of these if you study science.
This is the speed of light in a vacuum,
measured in metres per second.
This is Avogadro's number.
It's also called a mole.
It's the number of particles you'll have
if you measure out the molecular weight of a substance in grams.
Suffice to say, it's a very large value.
This is known as the elementary charge.
It's the electrical charge of an electron,
measured in coulombs.
This number is tiny.
And this is the age of the universe in seconds.
At least it was not so long ago.
Don't worry if you're not a scientist
and you're not familiar with these values.
What really matters to us
is that these are either very large or very small.
Let's take a look at what this notation means.
Here's the mole again.
And again, don't worry if you're not a scientist.
All you need to appreciate is that this is a very big number.
This part of the notation
is called the mantissa.
This part of the notation is known as the exponent.
To convert this notation
into something more familiar,
you have to float the decimal point
23 places to the right,
and then fill with zeros.
You can see that this is a very large value indeed,
with so many digits
that it occupies a lot of space when it's written down in full.
If you're able to use more digits in the mantissa,
you can express this value with greater precision.
Floating the point 23 places to the right,
just like last time,
gives us a more accurate value.
But look at all those zeros.
It's still an approximation,
just a better one than before.
So as you can see,
the number of digits you're allowed to use in the mantissa
governs the precision of the value written in this way.
Similarly, the number of digits available for the exponent
governs the range.
With only two digits for the exponent,
you wouldn't be able to float the point
any more than 99 places to the right.
You'll see why this is important in computer science soon.
Here's the charge on an electron again.
This time it's an example
of a very small number.
Notice that the exponent is a negative number.
This means that you have to float
the decimal point 19 places to the left
to get a more familiar form.
Clearly this is a very small fraction indeed.
So how does this apply to the representation
of real numbers in a digital computer?
This is a 16-bit register
inside a central processing unit.
In this theoretical processor, by design,
10 bits on the left have been allocated to the mantissa
and 6 bits on the right
have been allocated to the exponent.
The mantissa is stored in 2's complement
and so is the exponent.
An imaginary binary point is located
immediately to the right of the sine bit.
The sine bit is the leftmost bit in the register.
Historically, floating point formats
have varied from machine to machine.
For example, some put the exponent on the left
and the mantissa on the right
and some use sine and magnitude instead of 2's complement.
It wasn't until 1985
that the Institute of Electrical and Electronics Engineers
agreed on the standard format
used in most of today's computers.
I'll say more about the IEEE 754 standard in another video
but the format I'm going to describe in detail now
illustrates the fundamental principles rather well.
Furthermore, the format I'm going to describe now
is the one you're expected to know about
if you sit an A-level Computer Science exam in the United Kingdom.
Looking at this register
you can see that the sine bit of the mantissa is a 0
which, in 2's complement
means that the mantissa is a positive number.
In fact, it means that this 16-bit register
contains a positive number.
If the sine bit of the mantissa was a 1
you'd be looking at a negative number here.
You can also see that the exponent is positive
because the leftmost bit of the exponent is 0.
A positive exponent indicates that the binary point
should be floated to the right.
If the leftmost bit of the exponent was a 1 instead
you'd be looking at a negative exponent
indicating that the binary point should be floated to the left.
To convert this number into base 10
First, work out the value of the exponent in denary.
In this case, it's positive 3.
So we have something
times 2 to the power of 3.
Remember where the binary point is.
Float it 3 places to the right.
So here's the original number
in pure binary.
There's no need to concern yourself with the trailing 0's on the right-hand side.
They're insignificant.
Put this into a conversion gadget
and you'll arrive at 6.5 in base 10.
When you do this final conversion
remember that this is a positive number
so the leftmost 1 has a positive place value
in this case 4.
The original register contents
therefore represent the denary value 6.5.
Let's see another example.
Again, we have a 16-bit register
with 10 bits for the mantissa
and 6 for the exponent.
At a glance, you can see it's a positive mantissa
and a positive exponent
because they both start with 0.
First, work out the value of the exponent in denary.
It's positive 2.
So we have something times 2 to the power of 2.
Remember where the binary point is
and float it 2 places to the right.
So here's the original number
in pure binary without the trailing 0's.
Plug it into a conversion gadget
remembering that this is a positive number
so the leftmost 1 must be a positive place value.
And you'll arrive at 2.625 in base 10.
And here's one more example.
At a glance, you can see it's a positive value
because the mantissa is positive
but this time it's a negative exponent.
Work out the value of the exponent
in this case, minus 2.
So we have the original mantissa
times 2 to the power of minus 2.
Float the point 2 places to the left.
So here's the value in pure binary.
Plug this into a gadget
and this time we have 0.125.
Here are some conversions you can try yourself.
Pause the video now if you want to give them a go
and I'll show you the solutions in just a moment.
And here are the solutions.
Here's a couple more examples for you to try.
Notice that these values are represented with 4 bits for the mantissa
and 4 bits for the exponent.
Solutions in a moment. Pause the video if you want to give them a try.
And here are the solutions.
Let's see an example of a negative number.
You can see it's negative at a glance
because the first bit of the mantissa, the sign bit
is a 1 this time.
Using the same method as before
convert the exponent into denary.
So we have something times 2 to the power of 3.
Remember where the binary point is
and float it 3 places to the right.
Now, when you convert from pure binary
remember that the leftmost 1
has a negative place value.
So this time we have
minus 8 plus 4 plus 2 plus 0.5
which gives us minus 1.5.
And one more example.
This time the mantissa is negative
which means that the value in the register is negative
and the exponent is negative as well.
So the binary point will float to the left.
Convert the exponent into denary.
We have minus 2 so we have something times 2 to the power of minus 2.
Remember where the point is
and float it 2 places to the left.
When you convert the pure binary back into denary
remember that the leftmost 1
has a negative place value.
So we have minus 0.25 plus 0.125
which gives us minus 0.125.
Here are some negative number conversions
you can try for yourself.
Pause the video now if you want to give them a go
and I'll show you the solutions in just a moment.
And here are the solutions.
In the next video of this series
I'm going to talk about the relationship between range and precision.
