This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.
History
Date User Action Args
2009-12-04 23:23:06tim.peterssetrecipients: + tim.peters, terry.reedy, zooko, mark.dickinson, eric.smith
2009-12-04 23:23:06tim.peterssetmessageid: <1259968986.46.0.829447349056.issue7406@psf.upfronthosting.co.za>
2009-12-04 23:23:04tim.peterslinkissue7406 messages
2009-12-04 23:23:04tim.peterscreate