[Python-ideas] String and bytes bitwise operations

Ken Hilton kenlhilton at gmail.com
Fri May 18 23:58:28 EDT 2018


On Fri, 18 May 2018 13:49:58 -0300, Facundo Batista wrote:
> Once you think as the whole sequence of bytes as a sequence of bits (eight
times longer, of course), all questions are easly answered, see below...

I had never considered this before, but it seems very interesting.
Essentially that would make bytes1 ^ bytes2 be equivalent to

    (int.from_bytes(bytes1, sys.byteorder) ^ int.from_bytes(bytes2,
sys.byteorder)).to_bytes(max(len(bytes1), len(bytes2)), sys.byteorder)


rather than

    bytes(a ^ b for a, b in zip(bytes1, bytes2))

I like that idea more than my original elementwise idea.

​Thinking,
Ken Hilton;​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180519/58a5fb11/attachment-0001.html>


More information about the Python-ideas mailing list