add without carry
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Sep 15 05:19:20 EDT 2006
In <1158308274.680123.100070 at i42g2000cwa.googlegroups.com>, Hugh wrote:
> I would like to perform an addition without carrying of two integers...
> I've got no idea how to do this in python, although I've been using it
> for web/cgi/db work for a few years now.
Your description is a bit vague. What is `without carrying`? Do you want
to limit the result to a given bit length with a "wrap around" behavior if
the number gets too large to fit into those bits? Then this should do the
trick:
a = (b + c) & (2**bits - 1)
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list