def int_to_bin(int_val, width):
    """
    :param int_val: An unsigned integer.

    :param width: Maximum allowed width (in bits) of a unsigned integer.

    :return: Equivalent string value in Python's binary representation format
        ('0bxxx').
    """
    bin_tokens = []

    try:
        #   Python 2.6.x and upwards.
        bin_val = bin(int_val)
    except __HOLE__:
        #   Python 2.4.x and 2.5.x
        i = int_val
        while i > 0:
            word = i & 0xff
            bin_tokens.append(BYTES_TO_BITS[word])
            i >>= 8

        bin_tokens.reverse()
        bin_val = '0b' + _re.sub(r'^[0]+([01]+)$', r'\1', ''.join(bin_tokens))

    if len(bin_val[2:]) > width:
        raise IndexError('binary string out of bounds: %s!' % bin_val)

    return bin_val
dataset/ETHPy150Open drkjam/netaddr/netaddr/strategy/__init__.py/int_to_bin