如何显示浮点值的编码 [英] How to display the encoding of a floating-point value
本文介绍了如何显示浮点值的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用
%A
,但这不是我想要的格式。 例如,如果我的值是1.3416407,我想打印0x3FABBAE2,我不要0X1.5775C4P + 0。
解决方案
您可以使用联合,例如
#include< stdio.h>
#include< stdint.h>
union {
float f;
uint32_t i;
} u;
u.f = 1.3416407f;
printf(%#X\\\
,u.i);
How can we print the encoding of a floating-point value in C?
I know I can use %A
, but that isn't the format I want.
For example, if my value is 1.3416407, I want to print "0x3FABBAE2", I do not "0X1.5775C4P+0".
解决方案
You can use a union, e.g.
#include <stdio.h>
#include <stdint.h>
union {
float f;
uint32_t i;
} u;
u.f = 1.3416407f;
printf("%#X\n", u.i);
这篇关于如何显示浮点值的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文