Message95976
| Author |
tim.peters |
| Recipients |
eric.smith, mark.dickinson, terry.reedy, tim.peters, zooko |
| Date |
2009年12月04日.23:23:04 |
| SpamBayes Score |
6.9801565e-08 |
| Marked as misclassified |
No |
| Message-id |
<1259968986.46.0.829447349056.issue7406@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Terry, the language reference also says:
"""
For the purpose of shift and mask operations, a binary representation is
assumed, and negative numbers are represented in a variant of 2's
complement which gives the illusion of an infinite string of sign bits
extending to the left.
"""
That explains every result you saw:
3 = ...000011
2 = ...000010
1 = ...000001
-3 = ...111101
2 = ...000010
-1 = ...111111
3 = ...000011
-2 = ...111110
-3 = ...111101
-3 = ...111101
-2 = ...111110
3 = ...000011
2 = ...000010
3 = ...000011
1 = ...000001
-2 = ...111110
3 = ...000011
-3 = ...111101
In every case, the result is simply the xor of the inputs viewed as
infinite bitstrings. And it works exactly the same way if you use |, &,
<<, >>, or unary ~.
It's true that CPython's longs are /implemented/ via sign-magnitude, but
that should never be visible in the result of any operation. |
|