I have submitted a code-snippet shown below:
You have to mask the upper bits if you want to emulate a byte (like it would behave in C)
lw=(lw<<1) & 0xFF
of course, that is, if you keep
m set to 8 or it won't work.
m varies, you can compute (or pre-compute) the mask value like this:
mask_value = 2**m-1 lw=(lw<<1) & mask_value
(the aim of all this is to prefer arithmetic operations to string opertations which are more CPU/memory intensive)