def get_sub_register_value(sub_reg_bits_addr, bit_string):
    """
    Given a register address description string, and a register value
    string, return the bits from the value described by the address
    :param sub_reg_bits_addr: string of the form '48h-53h'
    :param bit_string: register value string of the form,
        '00000800031C1060EC9FBD3C00000000'
    :return: returns string of sub register: eg
    """
start, end = (int(x[:-1], 16) for x in sub_reg_bits_addr.split('-'))
value = int(bit_string, 16)
mask = (1 << end - start + 1) - 1
return ('%x' % (value >> start & mask)).upper()
Разрезание шестнадцатеричной строки по диапазону адресов