Decompose negative power of ten in finite series

121 Views Asked by At

Suppose we have numbers $10^{-1}, 10^{-2}, 10^{-3}, ..., 10^{-n}$. We need to represent each number by its closest representation that is less than original by means of finite sum of two in negative power. Given minimum "power boundary" $= -27$, we have: $10^{-1} = 2^{-4} + 2^{-5} + 2^{-8} + 2^{-9} + 2^{-12} + 2^{-13} + 2^{-16} + 2^{-17} + 2^{-20} + 2^{-21} + 2^{-24} + 2^{-25} + 2^{-27}$

Is there any way (formula or recursive method) to calculate values of powers of two without decomposing number manually? For example, we have system with input:

  • negative power of ten (for example, $-15$)
  • "power boundary" (for example, $-35$)

and output:

  • power of $1^{st}$ two
  • power of $2^{nd}$ two

    ...

  • power of $m^{th}$ two

1

There are 1 best solutions below

1
On BEST ANSWER

You're just asking for the binary representation of a number up to a precision of $2^{-p}$ for some $p$. The simplest algorithm is simply to first split into the integer part and fractional part, and then decompose each part separately.

Method

For the integer part, repeatedly divide by $2$, each time recording the remainder but continuing with the quotient, and then the remainders will form the binary digits starting from the ones to the twos to the fours and so on. For the fractional part, repeatedly multiply by $2$, each time recording the integer part but continuing with the fractional part, and then those integer parts will form the binary digits starting from the halves to the quarters to the eighths and so on.

Example

For example we want $13.79$ in binary.

Integer part = $13$. Repeatedly dividing the quotient by $2$ gives remainders:

13
 6 1
 3 0
 1 1
 0 1

So the integer part is $1101_2$.

Fractional part is $.79$. Repeatedly multiplying the fractional part by $2$ gives:

 .79
1.58
1.16
0.32
0.64
1.28
0.56
1.12
0.24
0.48
0.96
1.92
1.84
1.68
1.36
0.72
1.44
0.88
1.76
1.52
1.04
0.08
0.16
0.32  (we have seen .32 before so we know it will repeat)

So the fractional part is $.11\overline{00101000111101011100}_2$.

Therefore $13.79_{10} = 1301.11\overline{00101000111101011100}_2$.