Terry J. Reedy <tjre...@udel.edu> added the comment: I consider the binary bitwise operations, for negative ints, to be either undefined or wrongly implemented. Consider the following (3.1) >>> 3^2 1 >>> -3^2 -1 >>> 3^-2 -3 >>> -3^-2 3 >>> 2^3 1 >>> -2^3 -3
Something change sign just flips the sign of the result, sometimes it also changes the magnitude. From the viewpoint of arithmetic, and signed base-two representations, the latter seems senseless. The doc says only "The ^ operator yields the bitwise XOR (exclusive OR) of its arguments, which must be integers." But it does not define what bitwise XOR means for signed ints, as opposed to unsigned bit strings, possible interpreted as (unsigned) counts, which is the traditional domain of bit-operation definition. So there is no way to predict the result for negative ints. Or rather, the sensible prediction does not match the observed behavior. My impression is that Python longs are signed magnitudes. If so, the bitwise ops should arguably be the signed result of the op on the magnitudes. ---------- nosy: +tjreedy _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7406> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com