public final int DecodeDirectBits(int numTotalBits) throws IOException
  {
    int result = 0;
    for (int i = numTotalBits; i != 0; i--)
    {
      Range >>>= 1;
      int t = Code - Range >>> 31;
      Code -= (Range & t - 1);
      result = result << 1 | 1 - t;

      if ((Range & 0xFF000000) != 0)
        continue;
      Code = (Code << 8 | Stream.read());
      Range <<= 8;
    }

    return result;
  }