private int nextNBits(int bitsToGet) {
		byte b;
		byte next;
		byte next2next;
		int l = this.data.length - 1;
		int bp = this.bytePointer;

		if (this.fillOrder == 1) {
			b = this.data[bp];

			if (bp == l) {
				next = 0x00;
				next2next = 0x00;
			} else if ((bp + 1) == l) {
				next = this.data[bp + 1];
				next2next = 0x00;
			} else {
				next = this.data[bp + 1];
				next2next = this.data[bp + 2];
			}
		} else if (this.fillOrder == 2) {
			b = flipTable[this.data[bp] & 0xff];

			if (bp == l) {
				next = 0x00;
				next2next = 0x00;
			} else if ((bp + 1) == l) {
				next = flipTable[this.data[bp + 1] & 0xff];
				next2next = 0x00;
			} else {
				next = flipTable[this.data[bp + 1] & 0xff];
				next2next = flipTable[this.data[bp + 2] & 0xff];
			}
		} else {
			throw new RuntimeException("tag must be either 1 or 2."); //$NON-NLS-1$
		}

		int bitsLeft = 8 - this.bitPointer;
		int bitsFromNextByte = bitsToGet - bitsLeft;
		int bitsFromNext2NextByte = 0;
		if (bitsFromNextByte > 8) {
			bitsFromNext2NextByte = bitsFromNextByte - 8;
			bitsFromNextByte = 8;
		}

		this.bytePointer++;

		int i1 = (b & table1[bitsLeft]) << (bitsToGet - bitsLeft);
		int i2 = (next & table2[bitsFromNextByte]) >>> (8 - bitsFromNextByte);

		int i3 = 0;
		if (bitsFromNext2NextByte != 0) {
			i2 <<= bitsFromNext2NextByte;
			i3 = (next2next & table2[bitsFromNext2NextByte]) >>> (8 - bitsFromNext2NextByte);
			i2 |= i3;
			this.bytePointer++;
			this.bitPointer = bitsFromNext2NextByte;
		} else {
			if (bitsFromNextByte == 8) {
				this.bitPointer = 0;
				this.bytePointer++;
			} else {
				this.bitPointer = bitsFromNextByte;
			}
		}

		int i = i1 | i2;
		return i;
	}