def BitWidth(n: int):
    """ compute the minimum bitwidth needed to represent and integer """
    if n == 0:
        return 0
    if n > 0:
        return n.bit_length()
    if n < 0:
        # two's-complement WITHOUT sign
        return (n + 1).bit_length()