#include <iostream>
using namespace std;
union Float{
// public:
double m_Val;
unsigned long long m_Hex;
struct{
unsigned long long mantissa:52;
unsigned long long exponment:11;
unsigned long long sign: 1;
};
// public:
Float(double val=0.0) : m_Val(val){}
void SetMantissa(unsigned long long m) {
mantissa = m;
}
void SetExponment(unsigned long long e){
exponment = e;
}
void SetSign(unsigned long long s){
sign = s;
}
double GetVal(){return m_Val;}
unsigned long long GetHex(){return m_Hex;}
};
int main()
{
Float f;
f.SetExponment(0x400ULL);
f.SetMantissa(0x8000000000000ULL);
f.SetSign(0ULL);
cout << f.GetVal() << endl;
cout << f.GetHex() << endl << endl;
f.m_Val = 0.5;
cout << f.GetVal() << endl;
cout << f.GetHex() << endl;
cin.get();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdW5pb24gRmxvYXR7Ci8vIHB1YmxpYzoKCWRvdWJsZSBtX1ZhbDsKCXVuc2lnbmVkIGxvbmcgbG9uZyBtX0hleDsKCXN0cnVjdHsKCQl1bnNpZ25lZCBsb25nIGxvbmcgbWFudGlzc2E6NTI7CgkJdW5zaWduZWQgbG9uZyBsb25nIGV4cG9ubWVudDoxMTsKCQl1bnNpZ25lZCBsb25nIGxvbmcgc2lnbjogMTsKCX07Ci8vIHB1YmxpYzoKCUZsb2F0KGRvdWJsZSB2YWw9MC4wKSA6IG1fVmFsKHZhbCl7fQoJdm9pZCBTZXRNYW50aXNzYSh1bnNpZ25lZCBsb25nIGxvbmcgbSkJewoJCW1hbnRpc3NhID0gbTsKCX0KCXZvaWQgU2V0RXhwb25tZW50KHVuc2lnbmVkIGxvbmcgbG9uZyBlKXsKCQlleHBvbm1lbnQgPSBlOwoJfQoJdm9pZCBTZXRTaWduKHVuc2lnbmVkIGxvbmcgbG9uZyBzKXsKCQlzaWduID0gczsKCX0KCglkb3VibGUgR2V0VmFsKCl7cmV0dXJuIG1fVmFsO30KCXVuc2lnbmVkIGxvbmcgbG9uZyBHZXR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