![EBK COMPUTER SYSTEMS](https://www.bartleby.com/isbn_cover_images/8220101459107/8220101459107_largeCoverImage.jpg)
Explanation of Solution
Function definition for “float_i2f()” function:
The implementation for “float_i2f()”function is given below:
//Header file
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//Declare the float_bits in unsigned data type
typedef unsigned float_bits;
//Function declaration for float_i2f function
float_bits float_i2f(int i);
//Function definition for compute the bit length
int findBitsLength(int i)
{
//Check bit length
if ((i & INT_MIN) != 0)
{
//Returns value "32"
return 32;
}
//Assign the unsigned number
unsigned unum = (unsigned)i;
//Initializes the length is "0"
int len = 0;
//Check the length
while (unum >= (1<<len))
{
len++;
}
//Returns the length
return len;
}
//Function definition to generate mask
unsigned findBitsMask(int bl)
{
//Returns the bits mask
return (unsigned) -1 >> (32-bl);
}
//Fnction definition for compute (float)i
float_bits float_i2f(int i)
{
//Declare variable
unsigned signBit, exponentBit, fractionBit, remainingBit, exp_signBit,rp;
//declare variable bits and float bits
unsigned b, fb;
//Assign bias value
unsigned biasValue = 0x7F;
//If "i" is "0", then
if (i == 0)
{
//Assign all bits to "0"
signBit = 0;
exponentBit = 0;
fractionBit = 0;
//Returns the value
return signBit << 31 | exponentBit << 23 | fractionBit;
}
//If "i" is "INT_MIN", then
if (i == INT_MIN)
{
//Assign given value to each bit
signBit = 1;
exponentBit = biasValue + 31;
fractionBit = 0;
//Returns the value
return signBit << 31 | exponentBit << 23 | fractionBit;
}
//Assign sign bit is "0"
signBit = 0;
/* For two's complement */
/* If "i" is less than "0", then */
if (i < 0)
{
//Assign sign bit to "1"
signBit = 1;
//Assign "i" to "i - i"
i = -i;
}
/* Compute bits length by calling function "findBitsLength" */
b = findBitsLength(i);
//Compute float bits
fb = b - 1;
//Compute exponent value
exponentBit = biasValue + fb;
//Compute remaining bit value
remainingBit = i & findBitsMask(fb);
//If "fb" is less than "23", then
if (fb <= 23)
{
//Assign fraction bit and except bit value
fractionBit = remainingBit << (23 - fb);
exp_signBit = exponentBit << 23 | fractionBit;
}
//Otherwise
else
{
//Compute offset value
int offsetValue = fb - 23;
//To find round middle value
int rm = 1 << (offsetValue - 1);
//For round part
rp = remainingBit & findBitsMask(offsetValue);
//Assign fraction bit and except bit value
fractionBit = remainingBit >> offsetValue;
exp_signBit = exponentBit << 23 | fractionBit;
/*Check if it is round to even */
if (rp < rm)
{
}
//If round to odd, then
else if (rp > rm)
{
...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 2 Solutions
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)