Question: In this practice, we want to convert a 32-bit integer to IEEE 754 32-bit floating point representation. The goal is to obtain sign bit, exponent,
In this practice, we want to convert a 32-bit integer to IEEE 754 32-bit floating point
representation. The goal is to obtain sign bit, exponent, and fraction from an integer number.
Finding sign bit is very trivial, sign bit is 1 if number is negative, and 0 otherwise. Below I explain
hints on how to find exponent and fraction.
To find the exponent and fraction, we should convert an integer number into normalized
scientific format. For example:
1101 should be converted into 1.101 x 2
3
In general, we need to convert the number into 1.F x 2
E
representation. But how do we find
the normalized representations? Given a 32-bit normalized number, for example:
0000 0000 0000 0000 0000 0010 1000 1000
the key is to find the first none-zero bit from the left. This bit is the none-zero bit of the
normalized representation. For example, in the number above, bit at significance 2^9 is the
none-zero bit.
How you find this bit? I leave it up to you and your team to discuss best strategy
,
but when you find this bit, you have the normalized representation. How? In the normalized
representation formula:
1.F x 2
E
Where
E
is the significance of the number you found, 9 in our example. And
F
is all the bits on
the right side of it, 010001000 in our example. So the normalized representation of the number
above is
1.00010001000 x 2
9
Now that you have the normalized representation, you can extract exponent and fraction:
fraction = F = 00010001000
exponent = 127 + E = 127 + 9 = 136
Practice
Develop a C++ program to convert an integer to 32-bit floating point representation. Print
sign, exponent, and fraction and the end of your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
