add without carry

Hugh hugh.frater at gmail.com
Fri Sep 15 06:03:43 EDT 2006


Peter,

That was what I was thinking along the lines of, It's been two years
since I finished my CS degree and working in mechanical engineering
means I've nearly forgotten it all! :(

Thanks, I'll write a function in my app to handle this...

Hugh

> >>> (5 + 7) % 10
> 2
>
> In this context '%' is called 'modulo operator'. What John and Marc
> suggested is basically the same operation for the special case of binary
> numbers, i. e.
> 
> a % b == a & (b-1)
> 
> if a >= 0 and b == 2**N.
> 
> Peter




More information about the Python-list mailing list