单精度浮点数在vc++6.0中内存格式研究[1]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 loujing 的 blog

 

#include <iostream.h>

int main()
{
    float a=2;  /*这里分别让a等于2,-2,4,6,1,0.75,2.5,0.1,0  */
    char *p=(char*)&a;
    p+=3; /*将地址由高到低*/
    int line=0,temp=0;
    while(temp<4)
    {
        for(int i=7;i>=0;i--)
        {
            if(*p&(1<<i)) cout<<'1'; /*作与运算,如果和1与为1,说明该二进制是1,否则为0,其中左移运算让1不断往高位移动*/
            else cout<<'0';
            line++;
            if(line%4==0) cout<<' ';
        }
        temp++;

        p--;
    }
    cout<<endl;
    return 0;
}

 

 

测试结果及结果说明,给出msdn library上的解释(英文原版,原汁原味):

the format, then, for the various sizes is as follows:

format byte 1 byte 2 byte 3 byte 4 ... byte n
real*4 xxxx xxxx xmmm mmmm mmmm mmmm mmmm mmmm    
real*8 sxxx xxxx xxxx mmmm mmmm mmmm mmmm mmmm ...  mmmm mmmm
real*10 sxxx xxxx xxxx xxxx 1mmm mmmm mmmm mmmm ...  mmmm mmmm

本文关键:单精度浮点数在vc++6.0中内存格式研究
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top