简体   繁体   English

浮点转换-二进制->十进制

[英]Floating point conversion - Binary -> decimal

Here's the number I'm working on 这是我正在处理的号码

1 01110 001 = ____ 1 01110 001 = ____
1 sign bit, 5 exp bits, 3 fraction bits 1个符号位,5个exp位,3个小数位
bias = 15 偏差= 15

Here's my current process, hopefully you can tell me where I'm missing something 这是我目前的流程,希望您能告诉我我缺少什么

  1. Convert binary exponent to decimal 将二进制指数转换为十进制
    01110 = 14
  2. Subtract bias 减去偏差
    14 - 15 = -1
  3. Multiply fraction bits by result 将分数位乘以结果
    0.001 * 2^-1 = 0.0001
  4. Convert to decimal 转换为小数
    .0001 = 1/16

The sign bit is 1 so my result is -1/16, however the given answer is -9/16. 符号位是1,所以我的结果是-1/16,但是给出的答案是-9/16。 Would anyone mind explaining where the extra 8 in the fraction is coming from? 有人介意解释分数中额外的8来自何处吗?

You seem to have the correct concept, including an understanding of the excess-N representation, but you're missing a crucial point. 您似乎有正确的概念,包括对多余N表示的理解,但是您缺少关键点。

The 3 bits used to encode the fractional part of the magnitude are 001 , but there is an implicit 1. preceding the fraction bits, so the full magnitude is actually 1.001 , which can be represented as an improper fraction as 1+1/8 => 9/8 . 用于对幅度的小数部分进行编码的3位为001 ,但在分数位之前有一个隐式1. ,因此,完整的幅度实际上为1.001 ,可以表示为不正确的分数,如1+1/8 => 9/8

2^(-1) is the same as 1/(2^1) , or 1/2 . 2^(-1)1/(2^1)1/2

9/8 * 1/2 = 9/16 . 9/8 * 1/2 = 9/16 Take the sign bit into account, and you arrive at the answer -9/16 . 考虑符号位,您将得出答案-9/16

For normalized floating point representation, the Mantissa (fractional bits) = 1 + f. 对于规范化的浮点表示, 尾数 (分数位)= 1 + f。 This is sometimes called an implied leading 1 representation. 有时将其称为隐式前导1表示。 This is a trick for getting an additional bit of precision for free since we can always adjust the exponent E so that significant M is in the range 1<=M < 2 ... 这是一个免费获取额外精度的技巧,因为我们总是可以调整指数E,以使有效M处于1 <= M <2的范围内...

You are almost correct but must take into consideration the implied 1. If it is denormalized (meaning the exponent bits are all 0s) you do not add an implied 1. 您几乎是正确的,但必须考虑隐含的1。如果将它归一化 (意味着指数位全为0),则不要添加隐含的1。

I would solve this problem as such... 我会这样解决这个问题...

1  01110  001

bias = 2^(k-1) -1 =        14

Exponent = e - bias       

14 - 15 = -1
  1. Take the fractional bits ->> 001 取小数位->> 001
  2. Add the implied 1 ->> 1.001 添加隐含的1->> 1.001
  3. Shift it by the exponent, which is -1. 将其移动指数-1。 Becomes .1001 变成.1001
  4. Count up the values, 1(1/2) + 0(1/4) + 0(1/8) + 1(1/16) = 9/16 计算值1(1/2)+ 0(1/4)+ 0(1/8)+ 1(1/16)= 9/16
  5. With the a negative sign bit it becomes -9/16 随着负号位变为-9/16

hope that helps! 希望有帮助!

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

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