题目出的很不好,感觉没有标准.
#include <stdio.h>typedef unsigned float_bits;int float_f2i(float_bits f) {unsigned sign = f >> (31);unsigned exp = (f >> 23) & 0xff;unsigned frac = f & 0x7fffff;unsigned add = (frac & 0x3) == 0x3;unsigned E = exp-127;if(exp==0xff)return 0;else if(E>=0&&E<=23){frac = frac | 0x800000;//把隐藏位显示出来frac= frac >> (23-E);printf("0-23\n");}else if(E>23&&E<31){frac = frac | 0x800000;//把隐藏位显示出来frac= frac << (E-23);printf("23-31\n");}else if(E>=31){return 0x80000000;}return sign << 31 | frac;
}int main() {printf("%x\n", float_f2i(0xcF));return 0;
}