def pack_bitstring(bits):
 ret = ''
 i = packed = 0
 for bit in bits:
  if bit:
   packed += 128
  i += 1
  if (i == 8):
   ret += chr(packed)
   i = packed = 0
  else:
   packed >>= 1
 if ((i > 0) and (i < 8)):
  packed >>= (7 - i)
  ret += chr(packed)
 return ret

def pack_bitstring ( bits ) : ret = '' i = packed = 0 for bit in bits : if bit : packed += 128 i += 1 if ( i == 8 ) : ret += chr ( packed ) i = packed = 0 else : packed >>= 1 if ( ( i > 0 ) and ( i < 8 ) ) : packed >>= ( 7 - i ) ret += chr ( packed ) return ret
creates a string out of an array of bits .