[Python-ideas] bitwise operations on bytes
Josiah Carlson
jcarlson at uci.edu
Fri Dec 22 02:12:38 CET 2006
Terry Carroll <carroll at tjc.com> wrote:
> I would like to be able to have the capability of doing bitwise operations
> on a string-like field. For this example, I'll use strings, but as I
> understand it, the planned byte type would probably be more appropriate.
Strings won't exist in Py3k, so discussions about them aren't topical.
[snip]
> GLORPED = 0x10
> newchar = chr(ord(flags[1]) | GLORPED)
> flags = flags[0] + newchar + flags[2:]
You can get byte-wise operations on arrays today.
flags = array.array("B", f.read(4))
flags[1] |= GLORPED
Note that the only difference between 'bytes' and arrays with typecode
'B' is that the 'bytes' object may have more functionality, though the
functionality is not fully specified as of yet.
- Josiah
More information about the Python-ideas
mailing list