简体   繁体   English

将十进制转换为单精度IEEE 754

[英]Converting Decimal to Single-Precision IEEE 754

(-128.4875) base 10 to Single-Precision IEEE 754 (-128.4875)以10为基础的单精度IEEE 754

Converting (128.4875) base 10 to BINARY is: 1000 0000 . 将(128.4875)以10为基数的二进制转换为: 1000 0000。 0111 1100 1100 1100 1100... 0111 1100 1100 1100 1100 ...

The SCIENTIFIC NOTATION of the binary is: 1 . 二进制的科学符号是: 1。 0000 0000 1111 1001 1001 1001... x 2^7 0000 0000 1111 1001 1001 1001 ... x 2 ^ 7

The SIGN BIT is: 1 (1 bit) SIGN BIT是: 1 (1位)

The MANTISSA is 0000 0000 1111 1001 1001 100 (23 bits) MANTISSA是0000 0000 1111 1001 1001 100 (23位)

The EXPONENT is 7 + 127 = (134) base 10 = 1000 0110 (8 bits) 指数为7 + 127 =(134)以10为基数= 1000 0110 (8位)

Checking my answer against an online converter: 根据在线转换器检查我的答案:

http://s17.postimg.org/3pkw9glm7/mantissa.png

(not enough reputation to post in-line images)

I got everything BUT the last digit of the mantissa. 我得到了所有内容,但尾数的最后一位。 What I did was I chopped off the first 23 digits after the point in the scientific notation. 我所做的是我将科学计数法中的该点后的前23位数字砍掉了。

I got a 0 where the converter got a 1. Why is this so? 我得到0,转换器得到1。为什么会这样?

Do not “chop” the bits. 不要“砍”位。 Round the bits being removed: 舍入要删除的位:

  • If the bits being removed are less than 10000…, just remove them. 如果要删除的位少于10000…,则将其删除。
  • If the bits being removed are more than 10000…, remove them and add 1 to the remaining bits. 如果要删除的位数超过10000…,请删除它们,然后在剩余的位数上加1。
  • If the bits being removed are exactly 10000…, remove them and add 1 to the remaining bits if their last bit is 1. 如果要删除的位正好是10000…,请将它们删除,如果最后一位为1,则将1加到其余位上。

Thus: 从而:

  • 1011 0101 becomes 1011. (0101 is less than 1000….) 1011 0101变为1011。(0101小于1000…。)
  • 1011 1010 becomes 1100. (1010 is more than 1000….) 1011 1010变为1100。(1010大于1000…。)
  • 1011 1000 becomes 1100. (1000 is exactly 1000…, remaining bits are odd, so add one.) 1011 1000变成1100。(1000恰好是1000…,剩余位数为奇数,因此加1。)
  • 1010 1000 becomes 1010. (1000 is exactly 1000…, remaining bits are even, so do not add.) 1010 1000变为1010。(1000恰好是1000…,剩余位数为偶数,因此请勿加。)

(This is “round to nearest, ties to even”.) (这是“舍入到最接近,联系成偶”。)

Also, there is no mantissa in a floating-point number. 另外,浮点数中没有尾数。 The fraction portion is the significand. 分数部分是有效位数。 (A mantissa is logarithmic. A significand is linear.) (尾数是对数的。有效位数是线性的。)

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

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