Objects/Documentation
gamma23.py
Putting the length in the available bits · gamma23.py
Download ↓"""A bit-packed gamma count followed by the meaningful global-mode bits."""
from math import comb
import json
from global21 import study as payload,pack,unpack,unrank
from longueur22 import header
def decode(wire):
bits=''.join(format(b,'08b') for b in wire)
k=bits.find('1')
if k<0 or 2*k+1>=len(bits):raise ValueError('invalid gamma header')
n=int(bits[k:2*k+1],2);body=bits[2*k+1:];pos=1;count=0
if body[0]=='0':pos+=32*n
else:
while count<n:
if pos+7>len(body):raise ValueError('truncated block')