python implementation of a new integer encoding algorithm.
janhein.vanderburg at gmail.com
janhein.vanderburg at gmail.com
Thu Apr 9 05:33:13 EDT 2015
Op donderdag 19 februari 2015 19:25:14 UTC+1 schreef Dave Angel:
> I wrote the following pair of functions:
>
> def seven_code(n):
> acc = bytearray()
> if n == 0:
> acc.append(0)
> while n > 0:
> quotient, remainder = divmod(n, 128)
> acc.append(remainder)
> n = quotient
> acc[-1] |= 0x80 #add a stop bit to last byte
> return acc
>
> def seven_decode(sequ):
> acc = 0
> multiplier = 1
> for by in sequ:
> acc += (by & 0x7f) * multiplier
> if by > 0x7f:
> break
> multiplier *= 128
> return acc
>
> Here's a couple of ranges of output, showing that the 7bit scheme does
> better for values between 384 and 16379.
Thanks for this test; I obviously should have done it myself.
Please have a look at http://optarbvalintenc.blogspot.nl/2015/04/inputs-from-complangpython.html and the next two postings.
More information about the Python-list
mailing list