<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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