title: How to convert a binary fraction number into decimal fraction number in R?
body: <p>I need to write a function that converts a binary fraction number into decimal fraction number in R. e.g. <code>f(0.001) # 0.125</code></p>
  
  <p><strong>What I did:</strong> I searched for the related functions in R packages:</p>
  
  <pre><code>DescTools::BinToDec(0.001) # NA
  DescTools::BinToDec("0.001") # NA
  base::strtoi(0.001, base=2) # NA
  base::strtoi("0.001", base=2) # NA
  
  base::packBits(intToBits(0.001), "integer") # 0
  base::packBits(intToBits("0.001"), "integer") # 0
  
  compositions::unbinary(0.001) # 0.001
  compositions::unbinary("0.001") # NA
  </code></pre>
  
  <p>I searched in SOF, found  the following:</p>
  
  <pre><code>base2decimal &lt;- function(base_number, base = 2) {
    split_base &lt;- strsplit(as.character(base_number), split = "")
    return(sapply(split_base, function(x) sum(as.numeric(x) * base^(rev(seq_along(x) - 1)))))}
  base2decimal(0.001) # NA
  base2decimal("0.001") # NA
  </code></pre>
  
  <p>0.001 is:</p>
  
  <pre><code>(0 * 2^(-1)) + (0 * 2^(-2)) + (1 * 2^(-3)) # 0.125
  (0 * 1/2) + (0 * (1/2)^2) + (1 * (1/2)^3) # 0.125
  (0 * 0.5) + (0 * (0.5)^2) + (1 * 0.5^3) # 0.125
  </code></pre>
  
  <p>So, something like sum of the inner product <code>(0,0,1) * (0.5^1, 0.5^2, 0.5^3)</code> seems to finish the problem, I could not figure out how to do this in general case.</p>
  
  <p>javascript case:<br>
  <a href="https://stackoverflow.com/questions/33470049/how-to-convert-a-binary-fraction-number-into-decimal-fraction-number">How to convert a binary fraction number into decimal fraction number?</a>
  <a href="https://stackoverflow.com/questions/37109968/how-to-convert-binary-fraction-to-decimal">How to convert binary fraction to decimal</a>
  lisp case:<br>
  <a href="https://stackoverflow.com/questions/35408574/convert-fractions-from-decimal-to-binary">Convert fractions from decimal to binary</a></p>