Reputation: 21
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?
Upvotes: 2
Views: 3487
Reputation: 3132
If you have a "repeating decimal" in base 2 and you know what the repeating part of it is, it is possible to convert it to an exact rational number in p/q notation (where p and q are integers).
You can then use division to convert that number to ordinary decimal notation to as many digits of precision as you want. (In some cases you can even write the exact decimal value.)
The first step is to separate the binary number into its repeating and non-repeating parts.
Actually we want three things:
Suppose for example that the number is:
1.0001100110011... (binary)
where the last 0011 is repeated indefinitely.
We can break this down as follows:
The repeating part of the binary number is a geometric series and can be evaluated using the standard formula for such a series:
a + a*r + a*r^2 + a*r^3 + ... = a/(1 - r).
To apply this formula to the repeating digits:
For the example 1.00011011011... (binary),
Therefore
a/(1 - r) = (3/32) / (15/16) = 3/30 = 1/10,
which we can write as 0.1 (decimal).
The non-repeating part, of course, is 1 (decimal), so
1.00011011011... (binary) = 1 + 0.1 (decimal) = 1.1 (decimal).
In this example the decimal representation is terminating and exact.
There are many repeating binary fractions for which where the there is no exact, terminating decimal representation, for example,
0.01010101... (binary) = 1/3 = 0.3333... (decimal).
In such cases you must either decide to round off after some number of decimal digits or find and describe the repeating pattern of decimal digits.
Upvotes: 1
Reputation: 4487
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 ∞ .
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.......
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 ........
until you get enough precision.
Upvotes: 4