from typing import Optional
from typing import Iterable


def binidx(num: int, width: Optional[int] = None) -> Iterable[int]:
    """ Returns the indices of bits with the value `1`.

    Parameters
    ----------
    num : int
        The number representing the binary state.
    width : int, optional
        Minimum number of digits used. The default is the global value `BITS`.

    Returns
    -------
    binidx : list
    """
    fill = width or 0
    return list(sorted(i for i, char in enumerate(f"{num:0{fill}b}"[::-1]) if char == "1"))