64,648
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double c = 3.5;
int d[2];
memcpy( d, &c, 64 );
for( int i = 1; i >= 0; i-- )
{
for( int j = 31; j >= 0; j-- )
{
if( d[i]>>j & 0x01 )
cout<<"1";
else
cout<<"0";
if( j % 8 == 0 )
cout<<" ";
}
cout<<endl;
}
return 0;
}
printf("%p:%#x\n",&c, *(unsigned short*)&c);
printf("%p:%#x\n",(unsigned short*)&c+1, *((unsigned short*)&c+1));
printf("%p:%#x\n",(unsigned short*)&c+2, *((unsigned short*)&c+2));
printf("%p:%#x\n",(unsigned short*)&c+3, *((unsigned short*)&c+3));
0012FF5C:0
0012FF5E:0
0012FF60:0
0012FF62:0x400c
也就是说低地址:d[0]中是00000000 00000000 00000000 00000000 :这个是数据高位部分
d[1]中是01000000 00001100 00000000 00000000:高地址存的是数据的低位部分
double c = 3.5;
unsigned int d[2]; //改成这个无符号的比较好
memcpy( d, &c, 8);
printf("d[0]:%#x d[1]:%#x\n", d[0], d[1]);//你加这个打印出来