Home > Software design >  How do I reinterpret a uint64_t variable bits as a double as opposed to static_cast?
How do I reinterpret a uint64_t variable bits as a double as opposed to static_cast?

Time:10-01

uint64 value = 0x543;
double dval = *reinterpret_cast<double*>(&value);

I want dval to be of a certain value which when written in hexadecimal looks like this "0x543". Is there any danger doing this? Do you see a more efficient way of doing this?

Thanks

CodePudding user response:

Use std::bit_cast. In fact, the shown example is exactly what you are trying to do.

  • Related