Question: The function below (in c) accepts an integer (representing a floating point value) and returns and integer (representing a floating point value). The function multiplies

The function below (in c) accepts an integer (representing a floating point value) and returns and integer (representing a floating point value). The function multiplies the floating point by 2 and also handles the NaN cases. The last return statement actually multiplies the floating point by 2. Can you please show me or explain how "uf + (1<<23)" is equal to mutliplying the floating point by 2? Just confused on that part. Thanks!!

unsigned float_twice(unsigned uf) {

//uf = +-0 case.

if(uf==0 || uf == 0x80000000) return uf;

//NaN case.

if(((uf>>23) & 0xff) == 0xff) return uf;

//Tiny value, but non-zero case.

if(((uf>>23) & 0xff) == 0x00) {

return (uf & (1<<31)) | (uf<<1);

}

//Otherwise, Add 1 to exp value.

return uf + (1<<23);

}

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!