I need to write a function that converts a decimal fraction number into base 2 fraction number in R. e.g. f(0.125) # 0.001
What I did: I searched for the related functions in R packages:
DescTools::DecToBin(0.125) # ""
DescTools::DecToBin("0.125") # Not compatible with requested type: [type=character; target=integer].
0.125 is:
(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
The reverse side is the following and was solved here:
How to convert a binary fraction number into decimal fraction number in R?
Hence, a reverse-wind or something new hack seems to be necessary to overcome the problem.