[Python-ideas] String and bytes bitwise operations
rosuav at gmail.com
Fri May 18 14:15:52 EDT 2018
On Sat, May 19, 2018 at 2:32 AM, Chris Barker via Python-ideas
<python-ideas at python.org> wrote:
> On Thu, May 17, 2018 at 11:07 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
>> Steven D'Aprano wrote:
>>> But XORing bytes seems perfectly reasonable. Bytes are numbers, even if
>>> we display them as ASCII characters.
> actually, bytes are, well, bytes ;-) -- that is, 8 bits.
Grammatically, you appear to be disagreeing with the assertion that
bytes are numbers. Is that the case?
If you want to be extremely technical, an "octet" is a group of eight
bits (or eight musicians, but I haven't yet figured out how to send
musicians down an ethernet cable), and a "byte" isn't as rigidly
defined. But on modern PCs, you can fairly safely assume that they're
synonymous. I suppose you could argue that a "byte" is a patch of
storage capable of holding a number from 0 to 255, as opposed to being
the number itself, but that's getting rather existential :)
In Python, a "bytes" object represents a sequence of eight-bit units.
When you subscript a bytes , you get back an integer with the value
at that position. So if a collection of them is called a "bytes" and
one of them is an integer in range(0, 256), doesn't it stand to reason
that a byte is a number?
Maybe I'm completely misunderstanding your statement here.
 Yes, I'm aware that older versions of Python behaved differently. 
 I'm also aware that putting square brackets after the word "bytes"
could be interpreted as subscripting the 'bytes' type itself, rather
than creating a reference to a footnote. Ain't contextual grammar fun?
More information about the Python-ideas