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 CuriousLearner, docs@python, mark.dickinson, martin.panter, ncoghlan, tim.peters, wolma
Date 2018-07-15.07:32:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Well, all 6 operations "are calculated as though carried out in two's complement with an infinite number of sign bits", so I'd float that part out of the footnote and into the main text.  When, e.g., you're thinking of ints _as_ bitstrings, it's essentially useless to think of `n >> 13` as being equivalent to `n // 2**13`.

Quick:  what's ~0 >> 13?  Well, ~0 is an infinite string of 1 bits, so shifting it right by any finite number of bits doesn't change it.  That, mathematically, floor(~0 / 8192) = -1 is only interesting if you're thinking of ~0 as being an integer instead.

And, if you are, _then_ you need to know that the infinite string of 1 bits ~0 represents is viewed as being a 2's-complement representation of -1.  But so long as you're sticking to the bitstring view, the "2's complement" part is irrelevant to anything these 6 operations do.

Indeed, in the very earliest versions of Python, longs (but not ints!) were viewed as being 1's-complement infinite bitstrings, but "infinite string of sign bits" was just as applicable to what these operations did then.  The meaning of what these operations compute _as bitstrings_ is independent of how bitstrings are mapped to and from integers.  When longs changed from 1's-comp to 2's-comp only the latter changed; code using longs as bitstrings wasn't affected.

So, in all, there's quite a bit of background these telegraphic docs are glossing over.  You (Nick) don't seem to ever think of them as being bitstrings, but what the "bitwise operators" do was driven by the bitstring view.  That some of them can also be defined by arithmetic (+ - * /) is secondary.  It may well take more text to get that all across than is suitable here, though.
Date User Action Args
2018-07-15 07:32:52tim.peterssetrecipients: + tim.peters, mark.dickinson, ncoghlan, docs@python, martin.panter, wolma, CuriousLearner
2018-07-15 07:32:52tim.peterssetmessageid: <>
2018-07-15 07:32:52tim.peterslinkissue29710 messages
2018-07-15 07:32:52tim.peterscreate