def build_match_value(widths, value):
    res = ""
    for width in reversed(widths):
        mask = (1 << width) - 1
        val = value & mask
        num_bytes = (width + 7) / 8
        res = "{0:0{1}x}".format(val, 2 * num_bytes) + res
        value = value >> width
    return "0x" + res