II Floating Point Representation Using Strings Understanding how floating point numbers are
represented in memory, and how to manipulate that representation, is crucial to having a clear
view of how computer systems work and to writing efficient software. In this exercise, our goal
is to understand the floating point representation and how it is interpreted. We will convert a
simple floating number to its binary representation in the form of a string, then we will construct
our own representation to consolidate our understanding of the different components that make
up a float. 1. Given a floating point number as input: (a) Write a function that converts this
number to a string. This string is the binary representation of the floating point number. (b) Write
a function that takes the previously created string and switches the positions of the exponent and
the significand. The function returns the newly created string as output. Example: Given the
203.5 float as input: 1 (a) Converting the float to the string binary representation results in the
following string 01000011010010111000000000000000 The sign bit is highlighted in orange,
the exponent is highlighted in red, and the significand is highlighted in green. (b) In the string
representation we got previously, switching the exponent and significant results in the following
string 01001011100000000000000010000110 2. Transform the result of the previous question
from 32 bits to 64 bits (double-precision floatingpoint format). The function takes as input the 32
-bit string representation of a float and returns a string containing the 64-bit representation. In
order to obtain the 64-bit representation, you need to expand the exponent (from 8 bits to 11) and
significand (from 23 to 52 ). Example: (a) Starting from the string obtained in the question
(II.1.b): 01001011100000000000000010000110 (b) Expand the exponent (from 8 bits to 11) and
significand (from 23 to 52):
0100101110000000000000000000000000000000000000000000010000000110 III Floating
Point Representation Using Bit Manipulation Manipulating floats through their string
representation is not efficient or practical. In real-world applications, one would modify the
representation of floats using bit manipulation. Bit manipulation is useful beyond the scope of
modifying floating points. It's a powerful tool used in many applications, such as data
encryption, compression, image processing, and set manipulation. We want to perform the
previous steps using bit manipulation instead of string manipulation. Given a float as input, write
the following functions: 1. A function that prints the binary representation of an unsigned
integer. It takes an unsigned integer as input and prints its bits to the console standard output.
This is a helper function that should help you print the different intermediate values and check
your work. You can also use it to print the binary representation of a float by casting 1 that float
into an unsigned integer and .
II Floating Point Representation Using Strings Understanding how float.pdf
1. II Floating Point Representation Using Strings Understanding how floating point numbers are
represented in memory, and how to manipulate that representation, is crucial to having a clear
view of how computer systems work and to writing efficient software. In this exercise, our goal
is to understand the floating point representation and how it is interpreted. We will convert a
simple floating number to its binary representation in the form of a string, then we will construct
our own representation to consolidate our understanding of the different components that make
up a float. 1. Given a floating point number as input: (a) Write a function that converts this
number to a string. This string is the binary representation of the floating point number. (b) Write
a function that takes the previously created string and switches the positions of the exponent and
the significand. The function returns the newly created string as output. Example: Given the
203.5 float as input: 1 (a) Converting the float to the string binary representation results in the
following string 01000011010010111000000000000000 The sign bit is highlighted in orange,
the exponent is highlighted in red, and the significand is highlighted in green. (b) In the string
representation we got previously, switching the exponent and significant results in the following
string 01001011100000000000000010000110 2. Transform the result of the previous question
from 32 bits to 64 bits (double-precision floatingpoint format). The function takes as input the 32
-bit string representation of a float and returns a string containing the 64-bit representation. In
order to obtain the 64-bit representation, you need to expand the exponent (from 8 bits to 11) and
significand (from 23 to 52 ). Example: (a) Starting from the string obtained in the question
(II.1.b): 01001011100000000000000010000110 (b) Expand the exponent (from 8 bits to 11) and
significand (from 23 to 52):
0100101110000000000000000000000000000000000000000000010000000110 III Floating
Point Representation Using Bit Manipulation Manipulating floats through their string
representation is not efficient or practical. In real-world applications, one would modify the
representation of floats using bit manipulation. Bit manipulation is useful beyond the scope of
modifying floating points. It's a powerful tool used in many applications, such as data
encryption, compression, image processing, and set manipulation. We want to perform the
previous steps using bit manipulation instead of string manipulation. Given a float as input, write
the following functions: 1. A function that prints the binary representation of an unsigned
integer. It takes an unsigned integer as input and prints its bits to the console standard output.
This is a helper function that should help you print the different intermediate values and check
your work. You can also use it to print the binary representation of a float by casting 1 that float
into an unsigned integer and then calling this function. Example: (a) Given the 203.5 float as
input (use casting to pass it to the function). (b) The function prints:
01000011010010111000000000000000 2. A function that extracts the significand from the input
float using bit manipulation. The function takes a float as input and returns an unsigned int
containing the significand. Example: (a) Given the 203.5 float as input. (b) The function returns
an unsigned integer that has the following binary representation:
00000000010010111000000000000000 3. Use the previous function to extract the significand of
the input into an integer and print it. Example: 1 Casting should be done at the pointer level. 2 (a)
Using the previous example (2.b), Printing the significand as an integer returns: 4947968 4. A
function that extracts the exponent from the input float using bit manipulation. The function
takes a float as input and returns an unsigned int containing the exponent. Example: (a) Given
the 203.5 float as input. (b) After using the function to extract the exponent, the print function
would return the following: 0100001100000000000000000000000 5. A function that extracts the
sign bit from the input float using bit manipulation. The function takes a float as input and
2. returns an unsigned int containing the sign bit. Example: (a) Given the 203.5 float as input. (b)
After using the function to extract the sign, the print function would print the following:
00000000000000000000000000000000 6. A function that switches the significand and exponent
positions in float using bit operations. The function makes use of the previously developed code
and takes as input a float, and returns an unsigned integer containing the new representation.
Example: (a) Given the 203.5 float as input. (b) Running the input into the function and then
printing the results with the print function returns: 01001011100000000000000010000110 (c)
Printing the newly switched number as a float shows: 16777484.000000