什么将是浮动的值,如果我有一个二进制数为1111111111111111和使用英特尔处理器是32位的存储格式? [英] What will be the value in float if I have a binary number as 1111111111111111 and the storage formats used by Intel processors is 32 bits?

查看:351
本文介绍了什么将是浮动的值,如果我有一个二进制数为1111111111111111和使用英特尔处理器是32位的存储格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不重新present二进制数在浮点数。
我有一个十六进制数为FFFF,当我这个十六进制数转换成二进制我得到对应的二进制数为1111111111111111。
通过我的英特尔处理器使用的存储格式是32位装置1位用于符号,8位指数和用于尾数23位。
我有一些想法,但很困惑。
谁能帮我出了什么将会成为这个二进制数??

I have to represent a binary number in floating point number. I have a hexadecimal number as FFFF, when I am converting this hexadecimal number into Binary I am getting the corresponding binary number as 1111111111111111. The storage formats used by my Intel processor is 32 bits means 1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa. I have some idea but quite confused. Can Anyone help me out what will be the corresponding float value for this binary number??

推荐答案

只要尝试一下:

#include <stdio.h>

int main() {
  union {
    unsigned i;
    float f;
  } u;
  u.i = 0xffffffff;
  printf("%f\n", u.f);
  return 0;
}

打印 -NAN 。这个实验假设你其实想为0xffffffff 不是 0xFFFF的你的问题的状态。

prints -nan. This experiment assumes that you actually wanted 0xffffffff not 0xffff as your question states.

http://en.wikipedia.org/wiki/Single_$p$展望你发现指数pcision 0xFF的连同非零尾数被视为非数字。

Looking at http://en.wikipedia.org/wiki/Single_precision you find that exponent 0xFF together with a non-zero significand is treated as NaN.

如果你真的是在 0xFFFF的而已,至于你的问题写,那么code会打印 0.000000 ,但改变%F %G 9.18341e-41 。这是因为无论是整数,浮点使用相同的字节顺序,即你所谈论的对应位模式 0x0000ffff 浮动。

If you really are after 0xFFFF only, as your question writes, then the code will print 0.000000, but changing the %f to %g you get 9.18341e-41. This is because both the integer and the float use the same endianess, i.e. you are talking about the float corresponding to the bit pattern 0x0000ffff.

有你看,你现在就必须零的符号(即正数),零指数和非零尾数。根据同维基百科的文章,这次重新presents一个次正规数。因此,这是真的0xFFFF的∙2 -149 = 65535∙2 -149

There you see that you'll now have zero sign (i.e. positive), zero exponent and a non-zero significand. According to the same wikipedia article, this represents a subnormal number. So this is really 0xffff ∙ 2−149 = 65535 ∙ 2−149.

这篇关于什么将是浮动的值,如果我有一个二进制数为1111111111111111和使用英特尔处理器是32位的存储格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆