[Python-ideas] String and bytes bitwise operations

Facundo Batista facundobatista at gmail.com
Fri May 18 12:49:58 EDT 2018


2018-05-18 13:32 GMT-03:00 Chris Barker via Python-ideas
<python-ideas at python.org>:

> or would it operate on the whole sequence as a single collection of bits?

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...


> Would it be any different? Without thinking hard, it seems some operations,
> like AND and OR and XOR would be the same, but bit shifting would be
> different.

AND, XOR and OR are simple. Bit shifting will shift bits for the whole
bit sequence.


> And then what do you do if the two bytes objects are not the same length?

Pad with 0s to the left. Exactly the same that happen in

>>> 1 ^ 1231312312
1231312313

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
Twitter: @facundobatista


More information about the Python-ideas mailing list