namespace SharpCompress.Compressor.Rar.VM { internal class BitInput { /// the max size of the input internal const int MAX_SIZE = 0x8000; protected int inAddr; protected int inBit; /// internal BitInput() { InBuf = new byte[MAX_SIZE]; } internal byte[] InBuf { get; private set; } internal void InitBitInput() { inAddr = 0; inBit = 0; } /// /// also named faddbits /// /// internal void AddBits(int bits) { bits += inBit; inAddr += (bits >> 3); inBit = bits & 7; } /// /// (also named fgetbits) /// /// /// the bits (unsigned short) /// internal int GetBits() { // int BitField=0; // BitField|=(int)(inBuf[inAddr] << 16)&0xFF0000; // BitField|=(int)(inBuf[inAddr+1] << 8)&0xff00; // BitField|=(int)(inBuf[inAddr+2])&0xFF; // BitField >>>= (8-inBit); // return (BitField & 0xffff); return ((Utility.URShift((((InBuf[inAddr] & 0xff) << 16) + ((InBuf[inAddr + 1] & 0xff) << 8) + ((InBuf[inAddr + 2] & 0xff))), (8 - inBit))) & 0xffff); } /// Indicates an Overfow /// how many bytes to inc /// /// true if an Oververflow would occur /// internal bool Overflow(int IncPtr) { return (inAddr + IncPtr >= MAX_SIZE); } } }