简体   繁体   English

将以下以IEEE浮点数表示的32位二进制数(S,小数,指数)转换为十进制数

[英]Convert the following 32 bit binary numbers represented in IEEE floating point (S, Fraction ,Exponent) to decimal number

0 00000000000000000000000 0111011 0 00000000000000000000000 0111011

How would I do this problem I am lost. 我该怎么办,我迷路了。

Your bolding suggests that you might be a bit confused about the order of fields; 您的粗体显示您可能对字段的顺序有些困惑; IEEE generally uses the order sign,exponent,fraction for floating point numbers. IEEE通常对浮点数使用顺序符号,指数,分数 (Incidentally, this allows the use of twos-complement-integer sorts to sort IEEE floating point numbers, if there are no NaNs or other non-numeric values.) (顺便说一下,如果没有NaN或其他非数字值,这允许使用doubles-complement-integer排序对IEEE浮点数进行排序。)

So what are we looking at here? 那么我们在这里看什么呢? The first bit is the sign: 0. So we have a positive number. 第一位是符号:0。所以我们有一个正数。 (How to remember this? Go back to the allowed-to-use-integer-sort -- a leading one in a twos-complement integer means it's negative.) (如何记住这一点?回到允许使用的整数排序-二进制补码整数中的前导数字表示它是负数。)

The next eight bits are the exponent: also 0. This is the lowest possible exponent value; 接下来的八位是指数:也是0。这是可能的最低指数值。 it normally represents an unsigned integer biased by 127, or the value -127. 它通常表示一个无符号整数,偏差为127,即值-127。 However, the exponent value 0 is reserved for encoding subnormal numbers (numbers less than the smallest normally representable); 但是,指数值0保留用于编码次正规数(小于通常可表示的最小数)的数字; in this special case, the effective exponent is -126, but rather than representing the number 1.fraction * 2^exponent, a subnormal represents the number 0.fraction * 2^exponent. 在这种特殊情况下,有效指数为-126,而不是代表数字1.fraction * 2 ^指数,而次法线代表数字0.fraction * 2 ^指数。

Finally, we have the fraction, which is 0000000000000000111011 . 最后,我们得到分数0000000000000000111011 So our total number is 0.0000000000000000111011b * 2^-126. 因此,我们的总数为0.0000000000000000111011b * 2 ^ -126。 Converting this to decimal is left to the reader. 将其转换为十进制留给读者。

I agree with @addaon's previously posted answer. 我同意@addaon先前发布的答案。 In addition, the conversion can be done easily in some languages, including Java: 此外,可以使用某些语言(包括Java)轻松完成转换:

public class Test {
   public static void main(String[] unused) {
      int raw = 0b0000000000000000000000000111011;
      float f = Float.intBitsToFloat(raw);
      System.out.println(f);
   }
} 

(You need version 7 to get the binary literal, but the same thing can be done a little less directly in earlier versions) (您需要使用版本7来获取二进制文字,但是在较早的版本中,可以直接减少相同的操作)

The output is 8.3E-44, consistent with interpretation as a positive denormalized number, and with the conversion web site. 输出为8.3E-44,与解释为正的非规范化数字以及转换网站一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM