Creating a One Byte Floating Point Number
Introduction
Normally, IEEE 754 single precision floating point representation
is wonderful. It allows you to represent a wide range of floating point
values.
However, to explain how floating point addition and multiplication
work, it's nicer to use a much smaller representation for floating
point numbers. The additional bits in IEEE 754 single precision would
make the examples more difficult to read.
So, we're going to create a 1 byte floating point representation.
We'll loosely model it after IEEE 754 single precision.
Here are the specs.
- B7 is the sign bit.
- B6-3 is the exponent. There are 4 bits
for the exponent, which is represented in excess 7.
- B2-0 is the fraction. Three bits are used
to represent the fraction. There is a hidden 1.
- You can assume there's denormalized numbers, zero, infinity,
and NaN, but we won't worry about most of these categories.
Just to see if you know what's going on, represent the value
-4.5ten in this representation.
Convert -4.5ten to binary and you get
-100.1two.
Then write it in scientific notation as: - 1.001two X
22ten.
We can write this in our one byte format as:
| sign |
exponent |
fraction |
| 1 |
1001 |
001 |
Example 2
What if we wanted to represent 4.25ten
in this representation?
- Convert 4.25ten to binary and you get
100.01two.
- Then write it in scientific notation as:
1.0001two X 22ten.
- We need 4 bits after the radix point, but our representation
only permits 3 bits, so we either some method for rounding.
To make our represenation simple, we simply truncate additional
bits. So, the result is:
1.000two X 22ten.
- Using our one byte floating point representation, the value
is represented as:
| sign |
exponent |
fraction |
| 1 |
1001 |
000 |
On Your Own
Just for the fun of it, try coming up with an IEEE 754
halfword format using 11 bits for the fraction, 5 bits for
the exponent, and 1 sign bit. Represent a few numbers in
this representation. Decide what the bias should be. Model
it after IEEE 754 single precision.
Web Accessibility