将非终止二进制数转换为十进制 [英] Convert non terminating binary number to decimal

查看:119
本文介绍了将非终止二进制数转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何将不终止的二进制数(分数)转换为十进制.有人可以指导我如何做一个例子吗?

I don't know how to convert a non terminating binary number(fraction) to decimal . Can anybody guide me how to do with an example?

推荐答案

如果二进制数是一个无终止的整数,则它将是无限的(正数或负数).如何用十进制表示无限数?我认为是.

if the binary number is a unterminated integer, it would be infinite (positive or negative). How can you represent infinite number in decimal? I think it's .

否则,如果二进制数是浮点数,则表示祝贺.在许多浮点数标准(例如,IEEE 754)中,尾数由二进制模式表示,其中最高位的值为1/2,第二位的值为1/4等.您可以通过从左开始逐位累积每一位来将其转换为十进制.

else if the binary number is a float-point number, congratulations. In many standard of float-point number(e.g., IEEE 754), the mantissa is represented by a binary pattern in which the highest bit has a value of 1/2, the second bit has a value of 1/4 etc. So that you can convert it into decimal by accumulate each bit one by one from left.

例如,您有一个无终止的二进制模式

For example, you have a unterminated binary patter say

10111011101110111011 .......

10111011101110111011.......

要转换为十进制,只需将其累加为

to convert into decimal just accumulate them as

1 * 1/2 + 0 * 1/4 + 1 * 1/8 + 1 * 1/16 + 1 * 1/32 + 0 * 1/64 + 1 * 1/128 + 1 * 1/256 ........

1*1/2 + 0*1/4 + 1*1/8 + 1*1/16 + 1*1/32 + 0*1/64 + 1*1/128 + 1*1/256 ........

直到您获得足够的精度.

until you get enough precision.

这篇关于将非终止二进制数转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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