相关文章推荐
瘦瘦的刺猬  ·  JS ...·  4 月前    · 
性感的小虾米  ·  Help on "ERROR ...·  11 月前    · 
文武双全的荒野  ·  如何阻止Apple ...·  2 年前    · 
魁梧的筷子  ·  Uses of Class ...·  2 年前    · 
越狱的排球  ·  ruby on rails - PG ...·  2 年前    · 
7 int main( int argc, char const * argv[]) 9 printf( " %s\n " , " == in float representation == " ); 10 float f1 = 15213.0 ; 11 printf( " %x\n " , float2hexRepr(& f1));

结果如下:

1 == in float representation ==
2 466db400

为了更好看,打印出二进制:

 1 void hex2binaryStr(unsigned int x, char* str){
 2     unsigned int xCopy = x;
 3     for (int i = 0; i < 32; ++i)
 5         str[31 - i] = (xCopy & 1)? '1': '0';
 6         xCopy = xCopy >> 1;
10 void printBinary(char* str){
11     for (int i = 0; i < 32; ++i)
12     {
13         printf("%c", str[i]);
14         if (((1+i)%4 == 0) && ((1+i) != 32))
15         {
16             printf("%c", ',');
17         }
18     }
19     printf("\n");

结果如下:

1 == in float representation ==
2 466db400
3 0100,0110,0110,1101,1011,0100,0000,0000

THE END