def int2bin(n, nbits):
    """Converts an integer into a binary string.
    
    Parameters
    ----------
    n : int
        The integer value.
    nbits:
        The number of bits used to encode the value.
    """
    bits = []
    while n:
        n, remainder = divmod(n, 2)
        bits.insert(0, bool(remainder))
    while len(bits) < nbits:
        bits.insert(0, False)
    return bits
