xxx精度二进制定点表示有多少? [英] How much have xxx precision binary fixed point representation?

查看:27
本文介绍了xxx精度二进制定点表示有多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我转换为二进制定点表示方式时,我试图测量准确度有多少.首先我尝试使用这个 0.9375.我得到了二进制 0.1111.第二次我尝试使用这个 0.9377,我也得到了二进制 0.1111

他们之间没有什么不同.

另外我该如何解决这个问题?有没有其他办法?进行转换?

为了你的理解,我让我知道一些更多的例子,例如,如果我想将 3.575 转换为二进制,那么 3.575 就是 11.1001.但如果我再回到十进制然后 3.5625.与原值相差甚远.

解决方案

来自 类似问题,我们有:>

基数 2:二进制补码 4 整数,4 位小数

-2^3 2^2 2^1 2^0 .2^-1 2^-2 2^-3 2^-4-8 4 2 1 .0.5 0.25 0.125 0.0625

只有 4 个小数位,表示的数字只有 0.0625 的准确度

3.575 可能是 11.1001 = 2+ 1+ 0.5 + 0.0625 =>3.5625 低或 11.1010 = 2+ 1+ 0.5 + 0.125 =>3.625到高

这应该表明 4 位不足以准确表示3.5​​75".

要计算出需要乘以 2 的幂直到得到整数的位数:对于3.575",它相当多(50 个小数位).

3.575 * 2^2 = 14.3(非整数)3.575 * 2^20 = 3748659.23.575 * 2^30 = 3838627020.83.575 * 2^40 = 3930754069299.2(非整数)3.575 * 2^50 = 4025092166962381.0 (INTEGER) 我们需要 50 位!3.575 =>11.10010011001100110011001100110011001100110011001101

乘以 2 的幂将单词左移 (<<) 当没有剩余小数位时,表示该数字已完全表示,则移位次数为该数字需要的小数位.

对于定点,您最好考虑一下您的应用程序所需的精度级别.

I am trying to measure how much have accuracy when I convert to binary fixed point representation way. first I tried use this 0.9375. And I got the binary 0.1111. second I tried used this 0.9377 and I also got the binary 0.1111

There is nothing different between them.

Also how can I solve this problem? Is there any other way? To make converting ?

For your understand, I let me know some more example, For example, If I want to convert 3.575 to binary then 3.575 be 11.1001. but If I back to again to decimal then 3.5625. It so quite different on original value.

解决方案

From a similar question we have:

Base 2: Twos complement 4 integer, 4 bit fractional

-2^3  2^2  2^1  2^0  .  2^-1    2^-2    2^-3    2^-4
  -8    4    2    1  .   0.5    0.25   0.125  0.0625

With only 4 fractional bits the represented number only has an accuracy of 0.0625

3.575 could be 11.1001 = 2+ 1+ 0.5 + 0.0625 => 3.5625 to low
      or       11.1010 = 2+ 1+ 0.5 + 0.125  => 3.625  to high

This should indicate that 4 bits is just not enough to represent "3.575" exactly.

To figure out how many bit you would need multiply by a power of 2 until you get an integer: For "3.575" it is rather a lot (50 fractional bits).

3.575 * 2^2   = 14.3 (not integer)
3.575 * 2^20  = 3748659.2
3.575 * 2^30  = 3838627020.8
3.575 * 2^40  = 3930754069299.2 (not integer)
3.575 * 2^50  = 4025092166962381.0 (INTEGER) we need 50 bits!

3.575 => 11.10010011001100110011001100110011001100110011001101

Multiplying by a power of two shift the word to the left (<<) When there is no fractional bits left it means the number is fully represented, then number of shifts is the number of fractional bits required.

For fixed point you are better off thinking about the level of precision your application requires.

这篇关于xxx精度二进制定点表示有多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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