[Python-ideas] String and bytes bitwise operations

Chris Barker chris.barker at noaa.gov
Mon May 21 14:22:17 EDT 2018

On Sat, May 19, 2018 at 6:52 AM, Steven D'Aprano <steve at pearwood.info>

> Philosophical arguments about the nature of computer memory aside, byte
> objects in Python are collections of ints.

not when you start talking about bit-wise operations :-)

If a "byte" in python was an integer, then we'd use b**2 rather than b << 1

(yes, I know bit shifting can be more efficient, but I don't think that's
why it's there in python)

The entire point of bitwise operators is so that the bits themselves can be
accessed and manipulated.

> If you want those ints to represent something else, you're responsible
> for handling that (say, using the struct module).

yup -- with struct, and, hmm, maybe bitwise operators?

Anyway, as you say, this is a Philosophical (or semantic) point -- I don't
think it effects the discussion at hand.

However, when you talk about bit-shifting a bytes object, you do need to
decide if each byte is handled individually, or if they are one big



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180521/ddc25f69/attachment.html>

More information about the Python-ideas mailing list