Finish buildFloat():
It does three things:
It returns number.
// PURPOSE: To return the float with exponent 'exponent' and mantissa-field // 'mantissa'.
float buildFloat (int exponent, unsigned int mantissa )
{
unsigned int exponentPattern;
float number;
// YOUR CODE HERE to compute exponentPattern
// YOUR CODE HERE to turn off the hidden bit in the mantissa
*((unsigned int*)&number) = 0; // CHANGE THAT 0!
// It should be a bitwise integer expression
// combining exponentPattern and mantissa return 0; }
you have not mentioned any signed bit parameter in buildFloat function so I assume that you are using +ve no, you can change it var.raw.sign to -1 if required.
If you want anything else please comment.
#include <math.h>
#include <stdio.h>
float buildFloat (int exponent, unsigned int mantissa );
typedef union {
float f;
struct
{
unsigned int mantissa : 23;
unsigned int exponent : 8;
unsigned int sign : 1;
} raw;
} myfloat;
unsigned int convertToInt(int* arr, int low, int high)
{
unsigned f = 0, i;
for (i = high; i >= low; i--) {
f = f + arr[i] * pow(2, high - i);
}
return f;
}
int main()
{
buildFloat(128,1048576); for 2.250000 repesentation is 0 | 10000000 | 00100000000000000000000 0 | 128 |1048576
}
float buildFloat (int exponent, unsigned int mantissa ){
float number;
myfloat var;
var.raw.mantissa = mantissa;
var.raw.exponent = exponent;
var.raw.sign = 0; // make it -1 for negative no..
printf("The float value in"
" IEEE-754 representation is : \n");
printf("%f", var.f);
}
Get Answers For Free
Most questions answered within 1 hours.