Ejemplo n.º 1
0
        private static int getNumber(int nBits, sbyte[] buf, int bufPtr, int inc, BoolObject flag, IntObject mask, IntObject buffer, sbyte[] @in, IntObject nextIn)
        {
            // Extract and return a number (consisting of n_bits bits) from in stream
            IntObject number = new IntObject(1);

            if (nBits >= 3)
            {
                nextBit(buf, bufPtr + 3 * inc, number, mask, mask, buffer, @in, nextIn);
                if (nBits >= 4)
                {
                    nextBit(buf, bufPtr + 3 * inc, number, mask, mask, buffer, @in, nextIn);
                    if (nBits >= 5)
                    {
                        fillBuffer(mask, mask, buffer, @in, nextIn);
                        for (; nBits >= 5; nBits--)
                        {
                            number.Value = number.Value << 1;
                            mask.Value   = (int)((uint)mask.Value >> 1);
                            if (u32(buffer.Value) < u32(mask.Value))
                            {
                                number.incr();
                            }
                            else
                            {
                                buffer.sub(mask.Value);
                            }
                        }
                    }
                }
            }
            flag.Value = nextBit(buf, bufPtr, number, mask, mask, buffer, @in, nextIn);
            if (nBits >= 1)
            {
                nextBit(buf, bufPtr + inc, number, mask, mask, buffer, @in, nextIn);
                if (nBits >= 2)
                {
                    nextBit(buf, bufPtr + 2 * inc, number, mask, mask, buffer, @in, nextIn);
                }
            }

            return(number.Value);
        }
Ejemplo n.º 2
0
        private static bool nextBit(sbyte[] buf, int bufPtr1, IntObject number, IntObject testMask, IntObject mask, IntObject buffer, sbyte[] @in, IntObject nextIn)
        {
            fillBuffer(testMask, mask, buffer, @in, nextIn);
            int value = ((int)((uint)mask.Value >> 8)) * u8(buf[bufPtr1]);

            if (testMask != mask)
            {
                testMask.Value = value;
            }
            buf[bufPtr1] -= (sbyte)(u8(buf[bufPtr1]) >> 3);
            number.Value  = number.Value << 1;
            if (u32(buffer.Value) < u32(value))
            {
                mask.Value    = value;
                buf[bufPtr1] += 31;
                number.incr();
                return(true);
            }

            buffer.sub(value);
            mask.sub(value);

            return(false);
        }