浮点数小记

// print float bits
#include <iostream>
using namespace std;

int main()
{
        float num = 0.15625;
        int n = *(int*)(void*)#
        cout<<(n)<<endl;
        for(int i = 0; i < 32; ++i) {
                if(n & (1<<(31-i))) cout<<1;
                else cout<<0;
        }
        cout<<endl;
        return 0;
}

 摘自:http://blog.csdn.net/richerg85

(1.01)2*2(124-127) = 1.25 * 0.125 = 0.15625

对于浮点数一直有些不太明白,看了看博客就小记一下,以供以后查看 

浅谈计算机中浮点数的表达方法(IEEE 754)

原文地址:https://www.cnblogs.com/yaling/p/5080109.html