def encode(self, text):
text = text_type(text)<EOL>if '<STR_LIT:\x00>' in text:<EOL><INDENT>text = text.replace('<STR_LIT:\x00>', '<STR_LIT:U+0020>')<EOL><DEDENT>minval = Fraction(<NUM_LIT:0>)<EOL>maxval = Fraction(<NUM_LIT:1>)<EOL>for char in text + '<STR_LIT:\x00>':<EOL><INDENT>prob_range = self._probs[char]<EOL>delta = maxval - minval<EOL>maxval = minval + prob_range[<NUM_LIT:1>] * delta<EOL>minval = minval + prob_range[<NUM_LIT:0>] * delta<EOL><DEDENT>delta = (maxval - minval) / <NUM_LIT:2><EOL>nbits = long(<NUM_LIT:0>)<EOL>while delta < <NUM_LIT:1>:<EOL><INDENT>nbits += <NUM_LIT:1><EOL>delta *= <NUM_LIT:2><EOL><DEDENT>if nbits == <NUM_LIT:0>:  <EOL><INDENT>return <NUM_LIT:0>, <NUM_LIT:0><EOL><DEDENT>avg = (maxval + minval) * <NUM_LIT:2> ** (nbits - <NUM_LIT:1>)<EOL>return avg.numerator // avg.denominator, nbits<EOL>
Encode a text using arithmetic coding.

        Text and the 0-order probability statistics -> longval, nbits

        The encoded number is Fraction(longval, 2**nbits)

        Parameters
        ----------
        text : str
            A string to encode

        Returns
        -------
        tuple
            The arithmetically coded text

        Example
        -------
        >>> ac = Arithmetic('the quick brown fox jumped over the lazy dog')
        >>> ac.encode('align')
        (16720586181, 34)