def integer_repr(bin_str, fixed_width=False):
    """integer_repr(bin_str, fixed_width=False)

    Converts a binary representation to its integer number.

    Examples
    --------

    >>> integer_repr(b'11')
    3
    >>> integer_repr(b'-11')
    -3
    >>> integer_repr(b'0011')
    3

    The two's complement is returned when negative number with fixed width
    representation is given:

    >>> integer_repr(b'1101', fixed_width=True)
    -3
    >>> integer_repr(b'1101', fixed_width=False)
    13

    """
    if fixed_width:
        assert bin_str[:1] != b'-', 'invalid fixed-width binary representation'
        num = int(bin_str, 2)
        if bin_str[:1] == b'1':
            num -= 2 ** len(bin_str)
        return num
    else:
        return int(bin_str, 2)
