ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 21 Feb 2015 18:17:16 +0100Something like RealDigits in Sage?https://ask.sagemath.org/question/25881/something-like-realdigits-in-sage/Is there in Sagemath something like RealDigits in Mathematica for computing (binary) digits of any real number? (and not only for integers)
Can you please also explain how to transform back a non-integer binary string as '100.1000111001001' to the corresponding (approximated) base ten decimal? (not float)
Sat, 21 Feb 2015 16:07:06 +0100https://ask.sagemath.org/question/25881/something-like-realdigits-in-sage/Answer by Thorsten for <p>Is there in Sagemath something like RealDigits in Mathematica for computing (binary) digits of any real number? (and not only for integers)</p>
<p>Can you please also explain how to transform back a non-integer binary string as '100.1000111001001' to the corresponding (approximated) base ten decimal? (not float)</p>
https://ask.sagemath.org/question/25881/something-like-realdigits-in-sage/?answer=25884#post-id-25884To get the binary representation just add a .str(base=2) to the approximated value.
sage: a = pi + sqrt(2)
sage: a.n(digits=10).str(base=2)
'100.1000111001001001010100001111000010'
For the other direction the method RR is useful. Given as first argument the string and as second the base.
sage: s= a.n(digits=60).str(base=2)
sage: RR(s,2)
4.55580621596289
Sat, 21 Feb 2015 18:17:16 +0100https://ask.sagemath.org/question/25881/something-like-realdigits-in-sage/?answer=25884#post-id-25884