Answer the question
In order to leave comments, you need to log in
Python 3.4 What's the fastest way to pack a string in 7bit?
def encode_text(text, bit7):
if bit7:
res = list()
while text:
d = list()
r = list()
for i in range(len(text[:8])):
b = '{0:07b}'.format(ord(text[i]))
if not i:
r.append(b)
else:
r.append(b[:-i])
d.append(b[-i:])
if '' in r:
r.remove('')
for i in range(len(r)):
try:
res.append(d[i] + r[i])
except:
res.append('{0:08b}'.format(int(r[i],2)))
text = text[8:]
return res
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question