import decimal


def opt_tsresol(buf, _):
    """
    Figure out the time resolution, as a fraction of a second.

    The value returned is the inverse of the resolution, so 1000 means
    1/1000 second resolution, which is 0.001 seconds or 1 millisecond.
    """
    tsresol = buf[0]
    if tsresol & 0x80:
        opt_val = 2 ** (tsresol & 0x7F)
    else:
        opt_val = 10 ** tsresol
    return decimal.Decimal(opt_val)