If you are just wanting to do a memcpy style transaction you can try:
uint64_t x = 0xFEDCBA9876543212;
double dbl = *reinterpret_cast<double *>(&x);
Also, your test may not be doing what you want:
My test:
#include <cstdint>
#include <cstdio>
int main (void) {
// Move the underlying hex value through multiple types
uint64_t x = 0xFEDCBA9876543212;
double dbl = *reinterpret_cast<double *>(&x);
uint64_t y = *reinterpret_cast<uint64_t *>(&dbl);
// Check integrity of the result
printf("dbl: %llX\n", (uint64_t)dbl); //your test
printf("x: %llx\ny: %llx\n", x, y); //my test
return 0;
}
Output:
dbl: 8000000000000000
x: fedcba9876543212
y: fedcba9876543212
As you can see, the underlying binary value remains the same as it passes from x
to dbl
to y
, even though your current test printf("dbl: %llX\n", (uint64_t)dbl);
produces unexpected output.