Question: 4. In this question you will use the data type bit32 introduced in Lab 2 (i.e. an unsigned int). We will use the IEEE 754

 4. In this question you will use the data type "bit32"

4. In this question you will use the data type "bit32" introduced in Lab 2 (i.e. an unsigned int). We will use the IEEE 754 standard for floating point numbers, with 1 sign bit, 8 bits for the exponent, and 23 bits for the mantissa. For the following programming questions, place each function in a common file "fplib.c" for compiling and testing. You are not to use any C floating point data types i.e., float, double). You can use the bitwise operators as needed: and, or, not, xor, shift-right, and shift-left. (a) Write C functions to extract the sign, exponent, and fraction of a bit32 floating point number, returning their respective values as unsigned integers. The functions should be named sign, expon, and frac. (b) Write a function, float_32 (unsigned int sign, unsigned int exp, unsigned int frac), that returns a bit 32 representation of a number given a sign, exponent, and fraction values as unsigned integers. (c) Using the functions defined in (a) and (b), write a function fp add (bit32 x, bit32 y) that returns the addition of two bit32 values x and y as a floating point bit32 value. An algorithm for floating point addition is as follows: Start yes x=0 or y=0? return non-zero operand no Compare the exponents of the two numbers; shift the smaller number to the right until its exponent matches the larger exponent yes return 0 Add the mantissas mantissa = 0? no Normalize the sum if needed by shifting mantissa right and incrementing the exponent return answer 4. In this question you will use the data type "bit32" introduced in Lab 2 (i.e. an unsigned int). We will use the IEEE 754 standard for floating point numbers, with 1 sign bit, 8 bits for the exponent, and 23 bits for the mantissa. For the following programming questions, place each function in a common file "fplib.c" for compiling and testing. You are not to use any C floating point data types i.e., float, double). You can use the bitwise operators as needed: and, or, not, xor, shift-right, and shift-left. (a) Write C functions to extract the sign, exponent, and fraction of a bit32 floating point number, returning their respective values as unsigned integers. The functions should be named sign, expon, and frac. (b) Write a function, float_32 (unsigned int sign, unsigned int exp, unsigned int frac), that returns a bit 32 representation of a number given a sign, exponent, and fraction values as unsigned integers. (c) Using the functions defined in (a) and (b), write a function fp add (bit32 x, bit32 y) that returns the addition of two bit32 values x and y as a floating point bit32 value. An algorithm for floating point addition is as follows: Start yes x=0 or y=0? return non-zero operand no Compare the exponents of the two numbers; shift the smaller number to the right until its exponent matches the larger exponent yes return 0 Add the mantissas mantissa = 0? no Normalize the sum if needed by shifting mantissa right and incrementing the exponent return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!