不同数量指数和小数部分的比特格式之间转换 [英] Convert between formats with different number of bits for exponent and fractional part

查看:270
本文介绍了不同数量指数和小数部分的比特格式之间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图刷新浮动。我读,要求从格式的转换有一个练习:有K = 4,3位分数和偏差7.结果K = 3,4位分数和偏差= 3格式B
我们应该在必要时四舍五入。结果
格式之间例如:

  011 0000(值= 1)=====> 0111 000(值= 1)
010 1001(值= 25/32)=====> 0110 100(值= 3/4舍去)
110 1111(值= 31/2)=====> 1011 000(值= 16四舍五入)

问题:我无法弄清楚如何转换工作。首先,我设法做是正确的在某些情况下,但我的方法是格式化的位模式转换为十进制值,然后前preSS该值格式B.结果的位模式
但是,有没有办法以某种方式从一个位模式去其他没有这样做转换,只知道我们的1位扩展e和1降低分数?


解决方案

  

但是,有没有办法以某种方式从一个位模式去其他没有这样做转换,只知道我们的1位扩展e和1降低分数?


是,这是比通过十进制值去(如果转换为精确的十进制值,而不是一个近似这是唯一正确的)要简单得多。


011 0000(值= 1)
  再presents 1.0000 * 2 3-3
  真的是1.0 * 2 0 在自然二进制
  再$ P $ 1.000 psents * 2 7-7 为目标格式pre-格式
   =====> 0111 000(值= 1)

第二个例子:


010 1001(值= 25/32)
  再presents 1.1001 * 2 2-3
  真的是1.1001 * 2 1
  回合1.100 * 2 1 当我们想喝preSS一个数字,因为关系到甚至
  是1.100 * 2 6-7 pre-格式化
=====> 0110 100(值= 3/4舍去)

第三个例子:


110 1111(值= 31/2)
  再presents 1.1111 * 2 6-3
  真的是1.1111 * 2 3
  轮10.000 * 2 3 当我们想喝preSS一个数字,因为关系到偶数指上在这里和进位传播很长的路要走
  renormalizes成1.000 * 2 4
  是1.000 * 2 11-7 pre-格式化
   =====> 1011 000(值= 16四舍五入)

实施例2和3是中途例。好了,从4位馏分3位四舍五入分数,实例50%会中途案件反正。

在例2中, 1.1001 是接近 1.100 ,因为它是 1.101 。因此,如何结果选择?所选择的一个是一个以 0结束。在这里, 1.100

I am trying to refresh on floats. I am reading an exercise that asks to convert from format A having: k=3, 4 bits fraction and Bias=3 to format B having k=4, 3 bits fraction and Bias 7.
We should round when necessary.
Example between formats:

011 0000 (Value = 1)      =====> 0111 000 (Value = 1)  
010 1001 (Value = 25/32)  =====> 0110 100 (Value = 3/4 Rounded down)  
110 1111 (Value = 31/2)   =====> 1011 000 (Value = 16 Rounded up)  

Problem: I can not figure out how the conversion works. First of all I managed to do it correctly in some case but my approach was to convert the bit pattern of format A to the decimal value and then to express that value in the bit pattern of format B.
But is there a way to somehow go from one bit pattern to the other without doing this conversion, just knowing that we extend the e by 1 bit and reduce the fraction by 1?

解决方案

But is there a way to somehow go from one bit pattern to the other without doing this conversion, just knowing that we extend the e by 1 bit and reduce the fraction by 1?

Yes, and this is much simpler than going through the decimal value (which is only correct if you convert to the exact decimal value and not an approximation).

011 0000 (Value = 1)   
  represents 1.0000 * 23-3
  is really 1.0 * 20 in "natural" binary
  represents 1.000 * 27-7 to pre-format for the destination format
   =====> 0111 000 (Value = 1)

Second example:

010 1001 (Value = 25/32)  
  represents 1.1001 * 22-3
  is really 1.1001 * 2-1
  rounds to 1.100 * 2-1 when we suppress one digit, because of "ties-to-even"
  is 1.100 * 26-7 pre-formated
=====> 0110 100 (Value = 3/4 Rounded down)

Third example:

110 1111 (Value = 31/2)
  represents 1.1111 * 26-3
  is really 1.1111 * 23
  rounds to 10.000 * 23 when we suppress one digit, because "ties-to-even" means "up" here and the carry propagates a long way
  renormalizes into 1.000 * 24
  is 1.000 * 211-7 pre-formated
   =====> 1011 000 (Value = 16 Rounded up) 

Examples 2 and 3 are "halfway cases". Well, rounding from 4-bit fractions to 3-bit fractions, 50% of examples will be halfway cases anyway.

In example 2, 1.1001 is as close to 1.100 as it is to 1.101. So how is the result chosen? The one that is chosen is the one that ends with 0. Here, 1.100.

这篇关于不同数量指数和小数部分的比特格式之间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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