2
$\begingroup$

Given 0.4, the binary form is 0.0110011001(with 10 digits after ".") and 0.011001100110011001100110(with 24 digits after ".") without rounding. Is there any function that can do such converting? The BaseForm does not have option to define the digit number. What I did is to use RealDigits to extract all the needed digits and convert with PadRight and StringJoin. But this is a very lengthy and ineffective way.

$\endgroup$
0

1 Answer 1

4
$\begingroup$
d = 10;
N[FromDigits[RealDigits[.4, 2, d, -1]], d - 1]
 (* 0.0110011001 *)

d = 24;
N[FromDigits[RealDigits[.4, 2, d, -1]], d - 1]
  (* 0.011001100110011001100110 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.