def bit_length(num):
    """
    Measure the length of the number in bits.

    :param num: The number to measure.
    :return:    The minimal amount of bits needed to represent the number.
    """
    # `- 2` is due the output format of `bin`: `0bXXXXXXX`
    return len(bin(num)) - 2