def calc_max_bits(self, signed, values):
        """ Calculates the maximim needed bits to represent a value """
        b = 0
        vmax = -10000000
        
        for val in values:
            if signed:
                b = b | val if val >= 0 else b | ~val << 1
                vmax = val if vmax < val else vmax
            else:
                b |= val;
        bits = 0
        if b > 0:
            bits = len(self.bin(b)) - 2
            if signed and vmax > 0 and len(self.bin(vmax)) - 2 >= bits:
                bits += 1
        return bits
dataset/ETHPy150Open timknip/pyswf/swf/stream.py/SWFStream.calc_max_bits/original