[Python-ideas] String and bytes bitwise operations
Chris Barker - NOAA Federal
chris.barker at noaa.gov
Fri May 18 18:25:19 EDT 2018
>> 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?
Um, yes. Though I think for the rest of the conversation, it’s a
distinction that doesn’t matter.
> 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.
Sure — a byte, I think, is the smallest unit of memory that can be
addressed. It could be more or less that 8 bytes, but that wasn’t the
point either.
> 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 :)
No, I’m making the distinction that an eight bit byte is, well, eight
bits, that CAN represent a number from 0 to 255, or it can represent
any other data type — like one eighth of the bits in a float, for
instance. Or a bit field, or 1/2 a 16 bit int.
> In Python, a "bytes" object represents a sequence of eight-bit units.
> When you subscript a bytes [1], you get back an integer with the value
> at that position.
And when you print it, you get the ascii characters corresponding to
each byte....
So one element in a bytes object is no more an integer than a character....
> 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?
We use a decimal number (and ascii) to represent the bytes, as it’s
more human readable and consistent with other python types.
> Maybe I'm completely misunderstanding your statement here.
Again, it doesn’t much matter, until you get to deciding how to
bitshift an entire bytes object.
-CHB
More information about the Python-ideas
mailing list