natix.CompactDS.BitStream32.Read C# (CSharp) Method

Read() public method

public Read ( int numbits, BitStreamCtx ctx ) : System.UInt64
numbits int
ctx BitStreamCtx
return System.UInt64
        public UInt64 Read(int numbits, BitStreamCtx ctx)
        {
            int offset_r = (int)(ctx.Offset & 31);
            int offset_q = (int)(ctx.Offset >> 5);
            uint u;
            u = this.Buffer [offset_q];

            // cases:
            // 1) numbits is contained in q-th item
            // 2) numbits is in two items, q and q+1 th items
            // r is the remainder in the this.Offset bit-stream
            // q is the integer number containing the this.Offset bit

            // Console.WriteLine("u: {0}, offset_q: {1}, offset_r: {2}, mask: {3}, numbits: {4}",
            //		u, offset_q, offset_r, mask, numbits);

            UInt64 output;
            if (numbits + offset_r <= 32) {
                // case 1
                uint mask = (uint)((1ul << (numbits)) - 1);
                output = (u >> offset_r) & mask;
            } else {
                // case 2
                u >>= offset_r;
                int d1 = 32 - offset_r;
                // int d2 = numbits + offset_r - 32;
                int d2 = numbits - d1;
                uint v = this.Buffer [offset_q + 1] & ((1u << d2) - 1);
                v <<= d1;
                output = u | v;
            }
            ctx.Offset += numbits;
            return output;
        }

Same methods

BitStream32::Read ( BitStreamCtx ctx ) : bool

Usage Example

Ejemplo n.º 1
0
 public int Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     int min = 0;
     int galloping = 1;
     int check;
     int u = 0;
     while (true) {
         check = (1 << galloping) - 1;
         if (stream.Read (ctx)) {
             min = check + 1;
             ++galloping;
         } else {
             if (galloping == 1) {
                 if (stream.Read(ctx)) {
                     u++;
                 }
                 return u;
             } else {
                 u += min;
                 min = 0;
                 galloping = 1;
             }
         }
     }
 }
All Usage Examples Of natix.CompactDS.BitStream32::Read