Hi.
I do not think this is currently implemented in SymPy. If you would like to
implement it, that would be great! Basically, you just have to extend the
current Integer() to handle the base argument of int() (SymPy's Integer() is
already a wrapper around int()), and maybe add some methods to do whatever
things you need (change of base, etc.), and probably some kind of printer so
you don't get confused.
By the way, for what it's worth, gmpy's mpz type supports multiple bases too:
In [7]: from gmpy import mpz
In [8]: mpz("ee36", 16)
Out[8]: 60982
Aaron Meurer
On Jun 22, 2010, at 12:15 AM, John Connor wrote:
> It's not so much a printing issue as an ease of manipulation issue.
> In base 16 I can go:
> In [30]: hex = "ee36"
>
> In [31]: int(hex, 16)
> Out[31]: 60982
>
> In [32]: int(hex[0], 16)
> Out[32]: 14
>
> In [34]: int(hex[2], 16)
> Out[34]: 3
>
> I would like to be able to do that with any base, so I could say:
> base1000 = base(1000, 34987563294875623489756324576)
>
> if int(base1000[0], 1000) > 900: Do_Stuff()
> ...
>
> I was doing a bunch of iterations using divmod to pull apart the
> integers, but then I realized that conceptually what I was doing was
> just change of base operations with really large bases, and so I think
> I can really clean up my code a *lot* if I can figure out a way to do
> this. As far as printing goes, it isn't that important to me, because
> once the base goes over 52 or so, things would start to get
> incomprehensible (i.e.
> e'k"rw12""34yf'4vw'e1234rkhfv'b124214"".124'5gew""rgsfv X 1000^-31)
>
> Thanks,
> --Connor
>
>
> On Tue, Jun 22, 2010 at 12:13 AM, Ondrej Certik <[email protected]> wrote:
>> On Mon, Jun 21, 2010 at 9:54 PM, John Connor
>> <[email protected]> wrote:
>>> Hello all,
>>> I was wondering how sympy handles numbers with different bases
>>> (positional notation)? I would like to be able to convert a number
>>> from any base to any base, but because 'base' means so many different
>>> things in different contexts searching the docs / source has been
>>> fruitless. I am currently abusing pythons int(x[, base]) function,
>>> but it only works with bases up to 32, and I need to be able to use
>>> arbitrarily large bases. Can sympy do this? If someone could just
>>> point me in the right direction with the source or docs I would
>>> appreciate it very much.
>>
>> Is this just a printing issue? And a way to create new integers?
>>
>> Ondrej
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sympy?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.