[Python-ideas] Bitwise operations on bytes class
Nick Coghlan
ncoghlan at gmail.com
Wed Jun 18 00:10:26 CEST 2014
On 18 Jun 2014 07:34, "MRAB" <python at mrabarnett.plus.com> wrote:
>
> 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".
My bitbashing-with-Python work was all serial communications protocol
based, so logical shifts were what I wanted (I was also in the fortunate
position of being able to tolerate the slow speed of doing them in Python,
because HF radio comms are so slow the data streams to be analysed weren't
very big).
> 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?
Wanting an arithmetic shift would be a sign that one is working with
integers rather than arbitrary binary data, and ints or one of the fixed
width types from NumPy would likely be a better fit. So leaving that out of
any proposal sounds fine to me.
Cheers,
Nick.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140618/b99cdc74/attachment.html>
More information about the Python-ideas
mailing list