2013/11/8 Nathan Hurst <[email protected]>

> Is there a nicer way to pass python long ints (bigint) into C
> efficiently?  I'm currently cutting the value up into 64 bit chunks in
> python and passing in as an unsigned long*:
>
> cdef("int bigInt(int n, unsigned long* x);")
>
> x = sum(1 << i for i in [100,200,123])
> xs = []
> while x > 0:
>     xs.append(x & ((1 << 64) - 1))
>     x >>= 64
> print lib.bigInt(len(xs), xs)
>
> but this is quite slow, and it seems like this data must already be
> lurking somewhere in exactly the right form.
>

In Python3 you could use the to_bytes() method of ints,
but I could not find any way to have the same in python2.

Or just use hex(). You might have endianness issues, though.


-- 
Amaury Forgeot d'Arc
_______________________________________________
pypy-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to