private void WriteEncoding(int blockContentLength, AnsCodingTable blockTable) { ReversedMemoryStream reversedStream = new ReversedMemoryStream(); uint initialState = ConstructMask(blockTable.Denominator); AnsState stateIn = new AnsState(MaskBits, reversedStream, initialState); for (int i = 0; i < blockContentLength; i++) { int row = stateIn.ToInt(); int symbol = Block[i]; var validRows = blockTable[symbol]; while (!validRows.ContainsKey(row)) { stateIn.PopLower(); row = stateIn.ToInt(); } stateIn.Underlying = (uint)validRows[row]; } stateIn.Flush(); reversedStream.ReadToStream(Output); }