Message95976
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. |
|
Date |
User |
Action |
Args |
2009-12-04 23:23:06 | tim.peters | set | recipients:
+ tim.peters, terry.reedy, zooko, mark.dickinson, eric.smith |
2009-12-04 23:23:06 | tim.peters | set | messageid: <1259968986.46.0.829447349056.issue7406@psf.upfronthosting.co.za> |
2009-12-04 23:23:04 | tim.peters | link | issue7406 messages |
2009-12-04 23:23:04 | tim.peters | create | |
|