Converting an integer to a given base

866 views
Skip to first unread message

pascal

unread,
Mar 16, 2013, 5:38:37 PM3/16/13
to sage-s...@googlegroups.com
Hi,

How to perform base conversion with Sage ? Remember that Python has limited capability to convert to an arbitrary base. For instance, Python, by default, doesn't allow to convert to base 6. According to 


Sage can perform conversion to (say) base 6 :


sage: 2013.str(6)
'13153'
sage: int(_, 6)  
2013
sage:


but str conversion is limited  to base b <= 36.



Simon King

unread,
Mar 16, 2013, 5:56:28 PM3/16/13
to sage-s...@googlegroups.com
Hi Pascal,

On 2013-03-16, pascal <pascal...@gmail.com> wrote:
> How to perform base conversion with Sage ? Remember that Python has limited
> capability to convert to an arbitrary base. For instance, Python, by
> default, doesn't allow to convert to base 6. According to
>
> https://groups.google.com/forum/?hl=fr&fromgroups=#!newtopic/sage-support/sage-support/82CzhLK1NnE
>
> Sage can perform conversion to (say) base 6 :
>
>
> sage: 2013.str(6)
> '13153'
> sage: int(_, 6)
> 2013

Does the "digits()" method do what you want?

sage: a=23412341234
sage: a.digits(5)
[4, 1, 4, 4, 0, 4, 4, 2, 0, 2, 2, 4, 0, 4, 3]

Do
sage: a.digits?
to read the documentation.

Best regards,
Simon

pascal

unread,
Mar 16, 2013, 6:17:30 PM3/16/13
to sage-s...@googlegroups.com


Le samedi 16 mars 2013 22:56:28 UTC+1, Simon King a écrit :

Does the "digits()" method do what you want?

Yes, exactly  what I was looking for, many thanks!!

Kannappan Sampath

unread,
Mar 16, 2013, 6:23:02 PM3/16/13
to sage-s...@googlegroups.com
Hello! 

There is a ticket on trac: http://trac.sagemath.org/sage_trac/ticket/10253 which is meant to write this up in the documentation. 
I thought it would be worth mentioning just in case anybody wants to write this up. (I will get to this eventually, if nobody takes this up now. ;-) )

Regards, 
~KnS 


--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages