'Returns an instance of :class:`decimal.Decimal` for this
:class:`Decimal128`.'

def to_decimal(self):

    high = self.__high
    low = self.__low
    sign = (1 if (high & _SIGN) else 0)
    if ((high & _SNAN) == _SNAN):
        return decimal.Decimal((sign, (), 'N'))
    elif ((high & _NAN) == _NAN):
        return decimal.Decimal((sign, (), 'n'))
    elif ((high & _INF) == _INF):
        return decimal.Decimal((sign, (), 'F'))
    if ((high & _EXPONENT_MASK) == _EXPONENT_MASK):
        exponent = (((high & 2305807824841605120) >> 47) - _EXPONENT_BIAS)
        return decimal.Decimal((sign, (0,), exponent))
    else:
        exponent = (((high & 9223231299366420480) >> 49) - _EXPONENT_BIAS)
    arr = bytearray(15)
    mask = 255
    for i in range(14, 6, (-1)):
        arr[i] = ((low & mask) >> ((14 - i) << 3))
        mask = (mask << 8)
    mask = 255
    for i in range(6, 0, (-1)):
        arr[i] = ((high & mask) >> ((6 - i) << 3))
        mask = (mask << 8)
    mask = 281474976710656
    arr[0] = ((high & mask) >> 48)
    digits = tuple((int(digit) for digit in str(_from_bytes(bytes(arr), 'big'))))
    with decimal.localcontext(_DEC128_CTX) as ctx:
        return ctx.create_decimal((sign, digits, exponent))
