Sorry, I don't have the time to respond to all that (will do later),
but here are a few quick remarks about shifting and masking on long ints.
First, long ints have changes to a *one's complement* representation.
This was the only way that I could give ~0L the meaning of "all 1 bits".
Of course, as soon as you use any arithmetic on it, it changes to 0L,
and arithmetic operations (including unary "-") will never produce it.
Second, there's a bug in the implementation of long &, | and ^ when
one operand is negative and larger than the other; e.g., the outcome
for "1L & ~1000000L" is wrong. Fixed in 0.9.5.
I hope this explains most of what you've discovered.
"I told you the documentation was out of date :-)"
--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"What a senseless waste of human life"