def bit_length(int_type):
    """Return the number of bits necessary to represent an integer in binary,
    excluding the sign and leading zeros"""
    length = 0
    while int_type:
        int_type >>= 1
        length += 1
    return length