I did this program, which functions as expected, to know the bit representation of a float:
float x1=-675.78125;
int *pint1;
pint1=(int *)&x1;
for(int i=0;i<8*sizeof(float);i++)
{
if(*pint1&1)
{
cout<<1;
}
else
cout<<0;
*pint1>>=1;
}
But it doesn't work for a double:
double x=-675.78125;
int *pint;
pint=(int *)&x;
for(int i=0;i<8*sizeof(double);i++)
{
if(*pint&1)
{
cout<<1;
}
else
cout<<0;
*pint>>=1;
}
Could you explain me why this is so? how would you do it? Thank you so much for your help.