V
Virtual_X
As in IEEE754
double consist of
sign bit
11 bits for exponent
52 bits for fraction
i write this code to print double parts as it explained in ieee754
i want to know if the code contain any bug , i am still c++ beginner
#include <iostream>
using namespace std;
struct byte
{
bool bit[8]; // 8 = sizeof(double);
};
void pb(unsigned char *ch,byte *bin)
{
for(int i=0;i <=7;i++)
for(int o=7;o >=0;o--)
{
if(ch & 1<<o)
bin.bit[abs(o-7)]= true;
else
bin.bit[abs(o-7)]= false;
}
}
int main()
{
double x=215.2564878765465;
byte v[8];
pb(reinterpret_cast<unsigned char*>(&x),v);
//Printing the signbit
cout << "The sign bit\n" << v[0].bit[0] << endl;
cout <<
"\n---------------------------------------------------------\n";
/*--------------------------------------------------*/
//Printing the expoent bits = 11 bit
cout << "The exponent bits= 11 bits\n\n";
for(int i=1;i<8;i++)
cout << v[0].bit;
//still 4 bits
for(int i=0;i<4;i++)
cout << v[1].bit;
cout <<
"\n---------------------------------------------------------\n";
/*--------------------------------------------------*/
//Printing the fraction bits = 52 bit
//print the remain 4 bits
cout << "Fraction bits = 52 bit\n\n";
for(int i=4;i<8;i++)
cout << v[1].bit;
//print all the remain bits
for(int i=2;i<8;i++)
for(int o=0;o<8;o++)
{
cout << v.bit[o];
}
return 0;
}
double consist of
sign bit
11 bits for exponent
52 bits for fraction
i write this code to print double parts as it explained in ieee754
i want to know if the code contain any bug , i am still c++ beginner
#include <iostream>
using namespace std;
struct byte
{
bool bit[8]; // 8 = sizeof(double);
};
void pb(unsigned char *ch,byte *bin)
{
for(int i=0;i <=7;i++)
for(int o=7;o >=0;o--)
{
if(ch & 1<<o)
bin.bit[abs(o-7)]= true;
else
bin.bit[abs(o-7)]= false;
}
}
int main()
{
double x=215.2564878765465;
byte v[8];
pb(reinterpret_cast<unsigned char*>(&x),v);
//Printing the signbit
cout << "The sign bit\n" << v[0].bit[0] << endl;
cout <<
"\n---------------------------------------------------------\n";
/*--------------------------------------------------*/
//Printing the expoent bits = 11 bit
cout << "The exponent bits= 11 bits\n\n";
for(int i=1;i<8;i++)
cout << v[0].bit;
//still 4 bits
for(int i=0;i<4;i++)
cout << v[1].bit;
cout <<
"\n---------------------------------------------------------\n";
/*--------------------------------------------------*/
//Printing the fraction bits = 52 bit
//print the remain 4 bits
cout << "Fraction bits = 52 bit\n\n";
for(int i=4;i<8;i++)
cout << v[1].bit;
//print all the remain bits
for(int i=2;i<8;i++)
for(int o=0;o<8;o++)
{
cout << v.bit[o];
}
return 0;
}