Code: Alles auswählen
def rshift(s, bits, fill=0):
if bits not in xrange(0, 9):
raise Exception('bits must be within 0..8')
len_carry = 8 - bits
if isinstance(fill, str):
fill = (ord(fill) << len_carry) & 255
for c in s:
v = ord(c)
yield chr(v >> bits | fill)
fill = (v << len_carry) & 255
if __name__ == '__main__':
s = '12345'
print ''.join(bin(ord(i))[2:].zfill(8) for i in s)
print ''.join(bin(ord(i))[2:].zfill(8) for i in rshift(s, 1))
# with rotation
print ''.join(bin(ord(i))[2:].zfill(8) for i in rshift(s, 3, s[-1]))