def get_mask_and_shift_from_mask_string(mask_string, mask_char):
    """
    A mask string is composed of instruction bits and data.  The bits for a given
    piece of data, are indicated by the same variable character repeated.

    e.g. mask_string = "010101010fffffvvvvvggggg01010"

    This function takes the mask string, and a character 's', and returns the
    bit mask and shift amount to produce the value for that character variable.

    e.g. s = "f"
         instruction_word = 0xF0F0
         -> instruction_word = %1111 1111 0000 0000 1111 1111 0000 0000
         -> mask             = %0000 0000 0000 1111 1000 0000 0000 0000
         -> shift            = 15
         f = (instruction_word & mask) >> shift
         f = %0000 0000 0000 0000 1000 0000 0000 0000 >> 15
         f = 1
    """
    mask = 0
    for c in mask_string:
        mask <<= 1
        if c == mask_char:
            mask |= 1
    shift = 0
    if mask:
        mask_copy = mask
        while (mask_copy & 1) == 0:
            mask_copy >>= 1
            shift += 1
    return mask, shift