小编Mic*_*ael的帖子

使用c - printf将ieee 754 float转换为hex

理想情况下,以下代码将采用IEEE 754表示形式的浮点数并将其转换为十六进制

void convert() //gets the float input from user and turns it into hexadecimal
{
    float f;
    printf("Enter float: ");
    scanf("%f", &f);
    printf("hex is %x", f);
}
Run Code Online (Sandbox Code Playgroud)

我不太确定会出现什么问题.它将数字转换为十六进制数,但却是一个非常错误的数字.

123.1443 gives 40000000
43.3     gives 60000000
8        gives 0
Run Code Online (Sandbox Code Playgroud)

所以它正在做某事,我只是不太确定是什么.

帮助将不胜感激

c floating-point ieee-754

17
推荐指数
2
解决办法
4万
查看次数

标签 统计

c ×1

floating-point ×1

ieee-754 ×1