On Jan 14, 2009, at 12:04 PM, Crissy Ruffo wrote:

> I was looking into how SAGE handles arithmetic base(n).  Best I can
> tell, I use the function  Integer('string rep of number', base), but
> the answer returned is base(10), so I use the function .str(base) to
> convert it back to the desired base.  (thanks to the post by Ted
> Kosan  on converting Integers to base(n) strings) Does anyone know of
> something more direct?

Another method that might be useful is the "digits" command, i.e

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

Note that the ordering is little-endian, i.e. the units digit is  
always the first entry, the base^1 the second entry, etc.

If you are working with things of a limited size, a more "convenient"  
representation in terms of printing could be to use the p-adic  
numbers. I.e.

sage: R = Qp(13)
sage: R(100)
9 + 7*13 + O(13^20)
sage: R(230948213)
2 + 6*13 + 10*13^2 + 13^3 + 11*13^5 + 8*13^6 + 3*13^7 + O(13^20)
sage: a = R(10); a
10 + O(13^20)
sage: a + 5
2 + 13 + O(13^20)
sage: a + 13
10 + 13 + O(13^20)


- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to