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
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:
So the integer part is $1101_2$.
Fractional part is $.79$. Repeatedly multiplying the fractional part by $2$ gives:
So the fractional part is $.11\overline{00101000111101011100}_2$.
Therefore $13.79_{10} = 1301.11\overline{00101000111101011100}_2$.