Is there a simple way to manipulate std::cout so that it prints doubles in their hex representation? In other words, something equivalent to:
printf("%" PRIx64, *reinterpret_cast<uint64_t *>(&my_double));
To provide some context, I have a program which prints hundreds of floating-point results and I was wondering if there is that magical one-line hack that can print all of them in hex.
Take a look at std::hexfloat if you can use C++11
Example:
double k = 3.14;
std::cout<< std::hexfloat << k << std::endl;
prints: 0x1.91eb85p+1
You can use this
#include <iomanip> //Include this file
cout<<hex<<*reinterpret_cast<unsigned __int64 *>(&r);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With