一道c++题的算法?
c++编程输出long duoble型数12345067891023456的二进制位码?
请高手能给出程序谢谢了.
我有个在网上找的看不明白大家帮着侃侃
#include<iostream>
using namespace std;
void showbin(int n)
{
static char s[9];
for (int i =0;i<8;i++)
{
s[7-i] = n%2==0?48:49;
n/=2;
}
s[8] = 0;
cout<<s;
}
main()
{
double d = 12345.67891023456;
char t;
char* q;
int k;
for (int i=0;i<8;i++)
{
t = *((char*)&d+i);
showbin(int(t));
}
cout<<endl;
}