[Python-ideas] Bitwise operations on bytes class

MRAB python at mrabarnett.plus.com
Tue Jun 17 23:33:29 CEST 2014


On 2014-06-17 21:37, Antoine Pitrou wrote:
> Le 17/06/2014 15:35, Ethan Furman a écrit :
>>
>> I like the idea, but one question I have:  when shifting, are the
>> incoming bits set to 0 or 1?  Why?
>
> By convention, 0. Historically, that's how CPUs do it.
> (and also because it provides a quick way of multiplying / dividing by 2^N).
>
That's sometimes known as a "logical shift".

When shifting to the right, there's also the "arithmetic shift", which
preserves the most significant bit.

Do we need that too? (I don't think so.) If yes, then what should be
operator be? Just a 'normal' method call?


More information about the Python-ideas mailing list