System.IO.BitSplitter.GetInteger C# (CSharp) Méthode

GetInteger() public méthode

Return an unsigned long for the integer bits
public GetInteger ( int BitLength ) : ulong
BitLength int
Résultat ulong
        public ulong GetInteger(int BitLength)
        {
            ulong outval = 0L;
            int rshift, lshift;

            byte[] v = GetNext(BitLength);
            if (BitOffset == 0) { // landed on a byte-boundary
                rshift = 0;
            } else {
                rshift = 8 - BitOffset;
            }
            lshift = 8 - rshift;

            // This mess shifts the bits of a byte array by up to 8 places
            // and reverses byte order, joining the result into a ulong.
            int psh = 0;
            for (int i = v.Length - 1; i >= 0; i--) {
                int n0 = v[i] >> rshift;
                int n1 = (i > 0) ? (v[i-1] << lshift) : (0);

                outval += (ulong)(((n0 + n1) & 0xFF) << psh);
                psh += 8;
            }

            return outval;
        }

Usage Example

            private void ValidateTable(BitSplitter bs)
            {
                int pointer = (int)bs.GetInteger(8);
                if (pointer != 0) throw new DemuxException("Non-zero pointers are not currently supported");

                int table_id = (int)bs.GetInteger(8);
                if (table_id != 0x02) throw new DemuxException("Wrong table ID for PMT");

                SectionSyntax = bs.GetFlag();
                if (!SectionSyntax) throw new DemuxException("Invalid PMT: incorrect section syntax");
                bool zero = bs.GetFlag();
                if (zero) throw new DemuxException("Invalid PMT: zero bit wasn't zero");
            }
All Usage Examples Of System.IO.BitSplitter::GetInteger