def _int_str_to_bit_str(int_str, num_bits, msb_first):
    """
    Convert an integer string to num_bits bits string.
    Example:
        int_string_to_bit_str('0x5', 4) -> '0101'
        int_string_to_bit_str('0x3', 4, msb_first=false) -> '1010'
    """
    data = int(int_str, 0)  # use radix 0 to automatically deduce radix
    # convert to num_bits binary string with leading 0's
    bit_str = format(data, f'0{num_bits}b')
    return bit_str if msb_first else bit_str[::-1]