Ask Your Question

Something like RealDigits in Sage?

asked 2015-02-21 09:07:06 -0600

logomath gravatar image

updated 2015-02-21 16:36:29 -0600

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)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-21 11:17:16 -0600

Thorsten gravatar image

updated 2015-02-21 13:21:58 -0600

To 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)

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-02-21 09:07:06 -0600

Seen: 93 times

Last updated: Feb 21 '15

Related questions