【发布时间】:2018-10-07 04:41:03
【问题描述】:
所以我想我可以像这样打印float 的内部十六进制:
const auto foo = 13.0F;
const auto bar = reinterpret_cast<const unsigned char*>(&foo);
printf("0x%02hhX%02hhX%02hhX%02hhX\n", bar[0], bar[1], bar[2], bar[3]);
这个输出:
0x00005041
但是当我查看调试器时,它为foo 报告的十六进制是:
0x003EF830
谁能帮我理解为什么这不起作用以及我需要做些什么才能使它起作用?
【问题讨论】:
-
我猜你看到的奇怪值是
foo的address,而不是foo值。检查调试器输出。
标签: c++ floating-point hex printf ieee-754