public int getInstructionBits(int offset, int startbit, int size) throws MemoryAccessException {

		offset += (startbit / 8);
		startbit %= 8;
		int bytesize = (startbit + size - 1) / 8 + 1;

		byte[] bytes = new byte[bytesize]; // leave any unavailable bytes as 0 in result
		int readSize = memBuffer.getBytes(bytes, offset);
		if (offset == 0 && readSize == 0) {
			throw new MemoryAccessException("invalid memory");
		}

		int res = 0;
		for (int i = 0; i < bytesize; i++) {
			res <<= 8;
			res |= bytes[i] & 0xff;
		}

		res <<= 8 * (4 - bytesize) + startbit; //Move starting bit to highest position
		res >>>= 32 - size; // Shift to the bottom of int
		return res;
	}
Get bits from the instruction stream into an int
(packed in big endian format).  Uninitialized or 
undefined memory will return zero bit values.
@param offset offset relative start of this context
@param startbit is the index of the first bit to fetch
@param size is the number of bits to fetch
@return requested bit-range value
@throws MemoryAccessException if no bytes are available at first byte when (offset+bytestart/8==0).
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighParserContext.java