def bytes_needed(i):
    """
    Compute the number of bytes needed to hold arbitrary-length integer i
    """
    bn = 1
    while True:
        i >>= 7
        if i == 1:
            # negative sign bit
            return bn + 1
        elif i == 0:
            return bn
        i >>= 1
        bn += 1