Question

So I am trying to return the exponent value for f. If x is infinity or NaN I need to return Tmax. f is to be interpreted as the bit-level representations of single-precision floating point values and yes I mean to pass in an unsigned variable. I know I need to remove the appropriate value for the bias. I just cant figure out how. I can use any operations I want but only 8 of them (= does not count).

int float_exp(unsigned uf) {
    int mask = 2139095040;
    int hold;
    hold = uf & mask;
    if(mask == hold){
            return Tmax;
    } else {
        return ;// something here???
    }

}

I cant figure out how to get the exponent. Any help would be appreciated!

Was it helpful?

Solution 2

If the number is denormalized subtract 127 from the exponent. If it is not then subtract 126.

OTHER TIPS

Check the floating point format http://en.wikipedia.org/wiki/IEEE_754-1985

The binary exponent is in bits 23 through 30. So after masking against 0x7F800000, as you have done, you just need to shift what's left to the right by 23 bits and you have your binary exponent.

Then adjust for the bias, by subtracting it off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top