This fails, not surprisingly:
>>> 'abc' << 8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for <<: 'str' and 'int'
>>>
With ascii abc being equal to 011000010110001001100011 or 6382179, is there a way to shift it some arbitrary amount so 'abc' << 8 would be 01100001011000100110001100000000?
What about other bitwise operations? 'abc' & 63 = 100011 etc?
What you probably want is the bitstring module (see http://code.google.com/p/python-bitstring/). It seems to support bitwise operations as well as a bunch of other manipulations of bit arrays. But you should be careful to feed bytes into it (e.g.
b'abc'orbytes('abc')), not characters – characters can contain Unicode and occupy more than one byte.