#include #include // Thanks to: http://www.cplusplus.com/forum/beginner/85527/#msg458803 union { double myDouble; unsigned char myChars[sizeof(double)]; } test; int main() { unsigned char revChars[sizeof(double)]; test.myDouble = 3.0/256.0; for (int i = 0; i < 8; i++) { revChars[7-i] = test.myChars[i]; } for (int i = 0; i < 8; i++) { printf("%x ",revChars[i]); } std::cout << std::endl; int signBit = (revChars[0] & 0b10000000) >> 7; int exponentBits = ((int)((revChars[0] & 0b01111111) << 4)) | (int)(revChars[1] & 0b11110000) >> 4; printf("%x\n",((int)((revChars[0] & 0b01111111) << 4))); printf("%x\n",((int)(revChars[1] & 0b11110000) >> 4)); printf("%x\n", exponentBits); unsigned long long int fraction = ((long long int)(revChars[1] & 0b00001111) << 48) | ((unsigned long long int)(revChars[2]) << 40) | ((unsigned long long int)(revChars[3]) << 32) | (revChars[4] << 24) | (revChars[5] << 16) | (revChars[6] << 8) | (revChars[7]); printf("%llx\n",fraction); long long int onedFraction = fraction | 0x10000000000000; printf("%llx\n",onedFraction); std::cout << "myDouble: " << test.myDouble << std::endl; std::cout << "signBit: " << signBit << std::endl; std::cout << "exponentBits: " << exponentBits << std::endl; std::cout << "fraction: " << fraction << std::endl; double expValue = std::pow(2,exponentBits - 1023); std::cout << expValue << std::endl; double oneValue = (std::pow(2,-52) * onedFraction); printf("%d\n",oneValue); double newValue = expValue * oneValue; std::cout << newValue << std::endl; return 0; }