Integer arithmetic

James Gregory james at anchor.net.au
Thu Mar 27 06:55:03 EST 2003


On Thu, 2003-03-27 at 00:37, Grant Edwards wrote:
> In article <mailman.1048723363.12776.python-list at python.org>, James Gregory wrote:
> 
> >>> Am I so far off in thinking maybe this should be provided by
> >>> the language?
> >> 
> >> IMHO, you are.  "integral types with N bits ignoring overflows"
> > 
> > So wait, all you want to do is algebra in the ring Z_{2^32}?
> 
> Don't know about him, but what I want to do is 2's compliment
> add and subtract, bitwise and/or/not/xor and left/right shift
> operations on 8, 16, and 32 bit values.  If that's "algebra in
> the ring Z_{2^8|16|32}, then yes.

I was always better at number theory than coding theory. I think you
want to work in {Z_2}^32 - If you really wanna do it then I still hold
that just wrapping it all up into a class is the way to go.

It's not as crazy as it sounds, essentially what you're doing is
treating a 32 bit integer as a polynomial rather than an integral value.
In a language like C, it's a good way to do it. << gives you
multiplication by x, and if you want cyclic polynomials you can
construct a Galois field out of it IIRC. In python you probably actually
want to use something that *is* a polynomial. Possibly numeric python or
something could help out.

Grab a book on coding theory. Hamming is The Man IIRC.

James.







More information about the Python-list mailing list