简体   繁体   English

将十进制数转换为浮点表示法和 IEEE 754 格式

[英]Converting a decimal number to floating point notation and IEEE 754 format

I'm doing an assignment for one of my classes and I'm stuck on those two questions:我正在为我的一门课做作业,但我被这两个问题困住了:

  1. Express the decimal -412.8 using binary floating point notation using 11 fraction bits for the significand and 3 digits for the exponent without bias使用二进制浮点表示法表示十进制 -412.8 使用 11 个小数位作为有效数位和 3 位无偏差指数位

I think I managed to solve it, but my exponent has 4 bits not 3. I don't really understand how you can convert -412.8 to floating point notation using only 3 bit exponents.我想我设法解决了它,但我的指数有 4 位而不是 3。我真的不明白如何仅使用 3 位指数将 -412.8 转换为浮点表示法。 Here is how I tried to solve it:这是我尝试解决它的方法:

First of all, the floating point notation has three parts.首先,浮点表示法分为三个部分。 The sign part, 0 for positive numbers and 1 for negative numbers, the exponent part and finally the mantissa.符号部分,0 代表正数,1 代表负数,指数部分,最后是尾数。 The mantissa in this case includes the leading 1. Since the number is negative, the sign bit is going to be 1. For the mantissa, I first converted 412.8 to binary, which gave me 110011100.11 and then I shifted the decimal point to the left 8 times, which gives me 1.1001110011.这种情况下的尾数包括前导 1。由于数字是负数,符号位将是 1。对于尾数,我首先将 412.8 转换为二进制,得到 110011100.11,然后我将小数点向左移动8 次,这给了我 1.1001110011。 The mantissa is therefore 1100 1110 011 (11 bits as the teacher asked).因此,尾数是 1100 1110 011(老师要求的 11 位)。 Finally, the exponent is going to be 2^8, since I shifted the decimal 8 times to the right.最后,指数将是 2^8,因为我将小数点向右移动了 8 次。 8 is 1000 in binary. 8 是二进制的 1000。 So am I correct to assume that my floating point notation should be 1 1000 11001110011?那么我假设我的浮点符号应该是 1 1000 11001110011 是否正确?

  1. Represent the decimal number 16.1875×2-134 in single-precision IEEE 754 format.以单精度 IEEE 754 格式表示十进制数 16.1875×2-134。 I'm completely stuck on this one.我完全坚持这个。 I don't know how to convert that number.我不知道如何转换这个数字。 When I enter it in wolfram, the decimal number is way beyond the limit of the single precision format.当我在 wolfram 中输入时,十进制数远远超出了单精度格式的限制。 I do know that the sign bit is going to be 0 since the number is positive.我知道符号位将是 0,因为数字是正数。 I don't know what the mantissa is though, nor how to find it.我不知道尾数是什么,也不知道如何找到它。 I also don't know how to find the exponent.我也不知道如何找到指数。 Can someone guide me through this problem?有人可以指导我解决这个问题吗? Thanks.谢谢。

For 1, you appear to be correct -- there's no way to reperesent the exponent unbiased in 3 bits.对于 1,您似乎是正确的 - 无法以 3 位无偏的方式重新表示指数。 Of course, the problem says "3 digits" and doesn't define a base for the digits...当然,问题是“3位数”并且没有定义数字的基数......

2 is relatively straight-forward -- convert the value to binary gives you 10000.0011 then normalize, giving 1.00000011×2 -130 . 2 相对简单——将值转换为二进制会得到 10000.0011 然后归一化,得到 1.00000011×2 -130 Now -130 is too small for a single-precision exponent (minimum is -126), so we have to denormalize (continue shifting the point to get an exponent of -126), which gives us 0.000100000011×2 -126 .现在 -130 对于单精度指数来说太小了(最小值是 -126),所以我们必须反规范化(继续移动点以获得 -126 的指数),这给了我们 0.000100000011×2 -126 That's then our mantissa (with the 0 dropped) and an exponent field of 0: 0|00000000|00010000001100000000000 (vertical bars separating the sign/exponent/mantissa fields) or 0x00081800那就是我们的尾数(去掉 0)和 0 的指数字段:0|00000000|00010000001100000000000(垂直条分隔符号/指数/尾数字段)或 0x00081800

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

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